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.

compat: cleanup coding in compat_get_bitmap() and compat_put_bitmap()

In the functions compat_get_bitmap() and compat_put_bitmap() the
variable nr_compat_longs stores how many compat_ulong_t words should be
copied in a loop.

The copy loop itself is this:
if (nr_compat_longs-- > 0) {
if (__get_user(um, umask)) return -EFAULT;
} else {
um = 0;
}

Since nr_compat_longs gets unconditionally decremented in each loop and
since it's type is unsigned this could theoretically lead to out of
bounds accesses to userspace if nr_compat_longs wraps around to
(unsigned)(-1).

Although the callers currently do not trigger out-of-bounds accesses, we
should better implement the loop in a safe way to completely avoid such
warp-arounds.

Signed-off-by: Helge Deller <deller@gmx.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>

+4 -2
+4 -2
kernel/compat.c
··· 912 912 * bitmap. We must however ensure the end of the 913 913 * kernel bitmap is zeroed. 914 914 */ 915 - if (nr_compat_longs-- > 0) { 915 + if (nr_compat_longs) { 916 + nr_compat_longs--; 916 917 if (__get_user(um, umask)) 917 918 return -EFAULT; 918 919 } else { ··· 955 954 * We dont want to write past the end of the userspace 956 955 * bitmap. 957 956 */ 958 - if (nr_compat_longs-- > 0) { 957 + if (nr_compat_longs) { 958 + nr_compat_longs--; 959 959 if (__put_user(um, umask)) 960 960 return -EFAULT; 961 961 }