lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Wed, 2 Feb 2011 13:19:17 -0500
From:	"J. Bruce Fields" <bfields@...ldses.org>
To:	Konstantin Khorenko <khorenko@...allels.com>
Cc:	Neil Brown <neilb@...e.de>, linux-nfs@...r.kernel.org,
	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] NFSD: memory corruption due to writing beyond the stat
 array

On Tue, Feb 01, 2011 at 05:16:29PM +0300, Konstantin Khorenko wrote:
> Hi All,
> 
> i've found a bug which makes NFSD to corrupt memory due to writing beyond the stat array.
> 
> Initially this issue was found on 2.6.18-x RHEL5 kernel, but the same seems to be true for the current mainstream kernel (checked on 2.6.38-rc3).
> 
> ./fs/nfsd/vfs.c:
> static inline struct raparms *
> nfsd_get_raparms(dev_t dev, ino_t ino)
> {
> ...
>        // here we searched our file in a readahead cache
>        // but not found it
> ...
>          depth = nfsdstats.ra_size*11/10;
> ...
>        // some stuff, but "depth" is not changed
> ...
>          nfsdstats.ra_depth[depth*10/nfsdstats.ra_size]++;
> ...
> }
> 
> And here we write to the 12th array element
> (nfsdstats.ra_size*11/10*10/nfsdstats.ra_size == 11),

Actually, I think that's true only if ra_size is divisible by 10; if
not, then depth will be something *less* than ra_size*11/10, so
depth*10/ra_size will be something less than 11 (namely 10).

> This means that each time we did not find a file in a readahead cache we
> corrupt memory.

... and ra_size is set to 16 * min(2, numthreads/8), so I think you'll
hit this only if min(2, numthreads/8) (rounded down) is a multiple of 5?
So for example someone using a number of threads that's a power of 2
shouldn't hit this case.

> Fortunately in a kernel with NFSDv4 compiled in it corrupts
> (inc) NFS4 ops counter, but in a kernel with NFSDv4 disabled it corrupts (inc)
> some other data, that lays in the memory beyond nfsdstats.
> 
> Proposed fix is attached.

So after the fix:

> -	depth = nfsdstats.ra_size*11/10;
> +	depth = nfsdstats.ra_size;

depth*10/nfsdstats will always be 10 in this case.  Looks good.

Thanks for finding this!

--b.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ