mm/backing-dev.c: check user buffer length before copying data to the related user...
authorChen Gang <gang.chen@asianux.com>
Wed, 11 Sep 2013 21:22:44 +0000 (14:22 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 11 Sep 2013 22:58:03 +0000 (15:58 -0700)
'*lenp' may be less than "sizeof(kbuf)" so we must check this before the
next copy_to_user().

pdflush_proc_obsolete() is called by sysctl which 'procname' is
"nr_pdflush_threads", if the user passes buffer length less than
"sizeof(kbuf)", it will cause issue.

Signed-off-by: Chen Gang <gang.chen@asianux.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Tejun Heo <tj@kernel.org>
Cc: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/backing-dev.c

index 37d9edcd14cfbbff06510be795b4a6e125b95336..ce682f7a4f29d161189f47fd7e376d69bea2359d 100644 (file)
@@ -652,7 +652,7 @@ int pdflush_proc_obsolete(struct ctl_table *table, int write,
 {
        char kbuf[] = "0\n";
 
-       if (*ppos) {
+       if (*ppos || *lenp < sizeof(kbuf)) {
                *lenp = 0;
                return 0;
        }