From: Willy Tarreau <w@1wt.eu>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>,
Al Viro <viro@zeniv.linux.org.uk>,
Andy Lutomirski <luto@kernel.org>,
Linux FS Devel <linux-fsdevel@vger.kernel.org>,
Stephen Rothwell <sfr@canb.auug.org.au>,
Andrew Morton <akpm@linux-foundation.org>,
stable <stable@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] fs: Improve and simplify copy_mount_options
Date: Thu, 16 Jun 2016 07:45:25 +0200 [thread overview]
Message-ID: <20160616054525.GA6803@1wt.eu> (raw)
In-Reply-To: <CA+55aFy13+MYXU1tChx=Dysy_Ehhpc5Td+qrEaNv8smEygnuRQ@mail.gmail.com>
On Wed, Jun 15, 2016 at 02:42:33PM -1000, Linus Torvalds wrote:
> On Wed, Jun 15, 2016 at 2:01 PM, Andy Lutomirski <luto@amacapital.net> wrote:
> >
> > devtmpfsd does:
> >
> > *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
> >
> > where options points to the kernel stack. This is bad. do_mount_root
> > is similarly broken.
> >
> > Is there any reason that these things use sys_mount instead of do_mount?
>
> Not that I can see. But maybe copy_mount_options could also check for
> KERNEL_DS, and use a strncpy instead of a copy_from_user() for that
> case?
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 ?
Willy
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.
next prev parent reply other threads:[~2016-06-16 5:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-14 2:36 [PATCH v2 0/2] copy_mount_options improvements Andy Lutomirski
2016-06-14 2:36 ` [PATCH v2 1/2] fs: Improve and simplify copy_mount_options Andy Lutomirski
2016-06-15 23:50 ` Al Viro
2016-06-16 0:01 ` Andy Lutomirski
2016-06-16 0:42 ` Linus Torvalds
2016-06-16 5:45 ` Willy Tarreau [this message]
2016-06-16 5:59 ` Linus Torvalds
2016-06-16 6:57 ` Willy Tarreau
2016-06-16 7:02 ` Willy Tarreau
2016-06-16 7:08 ` Al Viro
2016-06-16 7:25 ` Willy Tarreau
2016-06-16 8:02 ` Al Viro
2016-06-16 8:20 ` Willy Tarreau
2016-06-16 8:38 ` Willy Tarreau
2016-06-17 3:12 ` Andy Lutomirski
2016-06-14 2:36 ` [PATCH v2 2/2] fs: Disallow mount options strings longer than PAGE_SIZE - 1 Andy Lutomirski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160616054525.GA6803@1wt.eu \
--to=w@1wt.eu \
--cc=akpm@linux-foundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=luto@kernel.org \
--cc=sfr@canb.auug.org.au \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).