Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pnfs/flexfiles: validate ds_versions_cnt is non-zero

nfs4_ff_alloc_deviceid_node() reads version_count from XDR without
checking it is non-zero. When a malicious NFS server sends a pNFS
LAYOUTGET response with version_count=0, kcalloc(0, ...) returns
ZERO_SIZE_PTR (0x10). The subsequent ds_versions[0] access in
nfs4_ff_layout_ds_version() and other callers dereferences this
invalid pointer, causing an out-of-bounds read.

Add a check for version_count == 0 after parsing it from XDR, before
the allocation.

The OOB read was confirmed with KASAN: null-ptr-deref in range
[0x0000000000000010-0x0000000000000017] from accessing ZERO_SIZE_PTR.

Fixes: d67ae825a59d ("pnfs/flexfiles: Add the FlexFile Layout Driver")
Reported-by: Klaudia Kloc <klaudia@vidocsecurity.com>
Reported-by: Dawid Moczadło <dawid@vidocsecurity.com>
Tested-by: Jenny Guanni Qu <qguanni@gmail.com>
Signed-off-by: Jenny Guanni Qu <qguanni@gmail.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>

authored by

Jenny Guanni Qu and committed by
Trond Myklebust
94545ffc b0ed1253

+5
+5
fs/nfs/flexfilelayout/flexfilelayoutdev.c
··· 97 97 if (unlikely(!p)) 98 98 goto out_err_drain_dsaddrs; 99 99 version_count = be32_to_cpup(p); 100 + 101 + if (version_count == 0) { 102 + ret = -EINVAL; 103 + goto out_err_drain_dsaddrs; 104 + } 100 105 dprintk("%s: version count %d\n", __func__, version_count); 101 106 102 107 ds_versions = kzalloc_objs(struct nfs4_ff_ds_version, version_count,