Message ID | 20160616054525.GA6803@1wt.eu (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, Jun 15, 2016 at 7:45 PM, Willy Tarreau <w@1wt.eu> wrote: > > Well, strncpy() would make the function behave differently depending on > the FS being used if called from the kernel for the reason Al mentionned. > OK devtmpfsd() passes a string, but if it's the FS itself which decides > to stop on a zero when parsing mount options, we'd probably rather use > memcpy() instead to ensure a consistent behaviour, like this maybe ? .. but that is exactly what Andy considers to be a problem: now it copies random kernel memory that is possibly security-critical. The kernel users that use this just pass in a string - it doesn't matter what the filesystem thinks it is getting, the uses were all kernel strings,, so the "copy_mount_options": should copy that string (and zero-fill the page that the filesystem may think it is getting). Linus -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/fs/namespace.c b/fs/namespace.c index 4fb1691..058b856 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2622,6 +2622,12 @@ void *copy_mount_options(const void __user * data) if (!copy) return ERR_PTR(-ENOMEM); + /* do_mount() may be called from the kernel */ + if (segment_eq(get_fs(), KERNEL_DS)) { + memcpy(copy, data, PAGE_SIZE); + return copy; + } + /* We only care that *some* data at the address the user * gave us is valid. Just in case, we'll zero * the remainder of the page.