From: "Luis R. Rodriguez" <mcgrof@kernel.org>
To: Kees Cook <keescook@chromium.org>
Cc: "Luis R. Rodriguez" <mcgrof@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Ingo Molnar <mingo@kernel.org>, Mel Gorman <mgorman@suse.de>,
Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>,
Jessica Yu <jeyu@redhat.com>,
Rusty Russell <rusty@rustcorp.com.au>,
Steven Whitehouse <swhiteho@redhat.com>,
deepa.kernel@gmail.com, Matt Fleming <matt@codeblueprint.co.uk>,
Alexey Dobriyan <adobriyan@gmail.com>,
Borislav Petkov <bp@suse.de>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
shuah@kernel.org, Linus Torvalds <torvalds@linux-foundation.org>,
Guenter Roeck <linux@roeck-us.net>,
linux-kselftest@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
"David S. Miller" <davem@davemloft.net>,
Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH v2 2/9] sysctl: add proper unsigned int support
Date: Wed, 17 May 2017 00:25:11 +0200 [thread overview]
Message-ID: <20170516222511.GH17314@wotan.suse.de> (raw)
In-Reply-To: <CAGXu5jL6Khgx0AeiZ7EZRHmsmB4vxVy+ZW8qZDgQcriBvb20ow@mail.gmail.com>
On Mon, Feb 13, 2017 at 12:19:51PM -0800, Kees Cook wrote:
> On Fri, Feb 10, 2017 at 4:36 PM, Luis R. Rodriguez <mcgrof@kernel.org> wrote:
> > ---
> > fs/proc/proc_sysctl.c | 15 +++++
> > kernel/sysctl.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++++--
> > 2 files changed, 170 insertions(+), 6 deletions(-)
> >
> > diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> > index d22ee738d2eb..73696a73a1ec 100644
> > --- a/fs/proc/proc_sysctl.c
> > +++ b/fs/proc/proc_sysctl.c
> > @@ -1031,6 +1031,18 @@ static int sysctl_err(const char *path, struct ctl_table *table, char *fmt, ...)
> > return -EINVAL;
> > }
> >
> > +static int sysctl_check_table_array(const char *path, struct ctl_table *table)
> > +{
> > + int err = 0;
> > +
> > + if (table->proc_handler == proc_douintvec) {
>
> Should this be inverted? i.e. explicitly allow proc_handlers instead
> of only rejecting douintvec?
The goal is to start avoiding the use of the silly arrays, and we start drawing
the line with proc_douintvec. The expectation then is that this list will grow
so the check should easily allow for growth of more exclusions for now, once we
are done we would hopefully only end up with strings that use arrays. For now
then we are limited to a specific check against the size of the parameter that
the proc handler uses, so for instance:
> > + if (table->maxlen != sizeof(unsigned int))
> > + err |= sysctl_err(path, table, "array now allowed");
> > + }
This uses unsigned int, I expect the check to be different for proc_dointvec_jiffies
once we vet no array uses exist for it. The way I think its best to expand on this
list is to later add:
else if (table->proc_handler == proc_dointvec_jiffies) {
...
}
If did the other way around and started this check with:
if (table->proc_handler != proc_douintvec)
return 0;
We'd still have to add a specific check for each handler for the actual expected
size for one element. So I would prefer to keep it this way for now. Once we have
vetted arrays are only needed for strings (and hopefully if we can change a few
ints users, not sure if proc is "uapi"; think it is so we might be shit out of luck),
then we'd only have a short white-list. Even so, the size check on the others is
probably good to leave, as such a check does not exist so we would not have to
nuke those old checks.
> > diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> > index 1aea594a54db..493bc05e546a 100644
> > --- a/kernel/sysctl.c
> > +++ b/kernel/sysctl.c
> > @@ -2243,6 +2243,155 @@ static int do_proc_dointvec(struct ctl_table *table, int write,
> > buffer, lenp, ppos, conv, data);
> > }
> >
> > +static int do_proc_douintvec_w(unsigned int *tbl_data,
> > + struct ctl_table *table,
> > + void __user *buffer,
> > + size_t *lenp, loff_t *ppos,
> > + int (*conv)(unsigned long *lvalp,
> > + unsigned int *valp,
> > + int write, void *data),
> > + void *data)
> > +{
> > + unsigned long lval;
> > + int err = 0;
> > + size_t left;
> > + bool neg;
> > + char *kbuf = NULL, *p;
> > +
> > + left = *lenp;
> > +
> > + if (*ppos) {
> > + switch (sysctl_writes_strict) {
> > + case SYSCTL_WRITES_STRICT:
> > + goto bail_early;
> > + case SYSCTL_WRITES_WARN:
> > + warn_sysctl_write(table);
> > + break;
> > + default:
> > + break;
> > + }
> > + }
>
> I wonder if this SYSCTL_WRITES_* test copy/pasting needs to be a function?
Good call. Folded in a new patch that does this. This stuff was a bit cryptic
so also folded in another patch which documented the strict stuff a bit in
kdoc form. Later with time we can move to new sphinx doc format and take
advantage of that.
<-- snip -->
> > +static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
> > + int write, void __user *buffer,
> > + size_t *lenp, loff_t *ppos,
> > + int (*conv)(unsigned long *lvalp,
> > + unsigned int *valp,
> > + int write, void *data),
> > + void *data)
> > +{
> > + unsigned int *i, vleft;
> > +
> > + if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
> > + *lenp = 0;
> > + return 0;
> > + }
> > +
> > + i = (unsigned int *) tbl_data;
> > + vleft = table->maxlen / sizeof(*i);
> > +
> > + /*
> > + * Arrays are not supported, keep this simple. *Do not* add
> > + * support for them.
> > + */
> > + if (vleft != 1) {
> > + *lenp = 0;
> > + return -EINVAL;
> > + }
> > +
> > + if (!conv)
> > + conv = do_proc_douintvec_conv;
> > +
> > + if (write)
> > + return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
> > + conv, data);
> > + return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
> > +}
>
> I like the split of read/write. That makes things easier to review.
Great.
Luis
next prev parent reply other threads:[~2017-05-16 22:25 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-29 19:29 [PATCH] " Luis R. Rodriguez
2017-01-30 12:56 ` Alexey Dobriyan
2017-02-01 19:56 ` Luis R. Rodriguez
2017-02-09 1:28 ` Luis R. Rodriguez
2017-02-09 1:32 ` Luis R. Rodriguez
2017-02-11 0:36 ` [PATCH v2 0/9] sysctl: add and fix " Luis R. Rodriguez
2017-02-11 0:36 ` [PATCH v2 1/9] sysctl: fix lax sysctl_check_table() sanity check Luis R. Rodriguez
2017-02-13 20:13 ` Kees Cook
2017-02-11 0:36 ` [PATCH v2 2/9] sysctl: add proper unsigned int support Luis R. Rodriguez
2017-02-13 20:19 ` Kees Cook
2017-05-16 22:25 ` Luis R. Rodriguez [this message]
2017-02-11 0:36 ` [PATCH v2 3/9] sysctl: add unsigned int range support Luis R. Rodriguez
2017-02-13 20:21 ` Kees Cook
2017-02-11 0:36 ` [PATCH v2 4/9] test_sysctl: add dedicated proc sysctl test driver Luis R. Rodriguez
2017-02-13 20:27 ` Kees Cook
2017-02-11 0:36 ` [PATCH v2 5/9] test_sysctl: add generic script to expand on tests Luis R. Rodriguez
2017-02-13 20:30 ` Kees Cook
2017-05-16 22:55 ` Luis R. Rodriguez
2017-02-11 0:36 ` [PATCH v2 6/9] test_sysctl: test against PAGE_SIZE for int Luis R. Rodriguez
2017-02-11 0:36 ` [PATCH v2 7/9] test_sysctl: add simple proc_dointvec() case Luis R. Rodriguez
2017-02-13 22:00 ` Kees Cook
2017-05-16 22:46 ` Luis R. Rodriguez
2017-02-11 0:36 ` [PATCH v2 8/9] test_sysctl: add simple proc_douintvec() case Luis R. Rodriguez
2017-02-11 0:36 ` [PATCH v2 9/9] test_sysctl: test against int proc_dointvec() array support Luis R. Rodriguez
2017-02-13 22:07 ` Kees Cook
2017-05-16 22:40 ` Luis R. Rodriguez
2017-02-13 20:11 ` [PATCH v2 0/9] sysctl: add and fix proper unsigned int support Kees Cook
2017-05-19 3:35 ` [PATCH v3 0/5] sysctl: few fixes Luis R. Rodriguez
2017-05-19 3:35 ` [PATCH v3 1/5] sysctl: fix lax sysctl_check_table() sanity check Luis R. Rodriguez
2017-05-22 22:40 ` Andrew Morton
2017-05-19 3:35 ` [PATCH v3 2/5] sysctl: kdoc'ify sysctl_writes_strict Luis R. Rodriguez
2017-05-19 3:35 ` [PATCH v3 3/5] sysctl: fold sysctl_writes_strict checks into helper Luis R. Rodriguez
2017-05-19 3:35 ` [PATCH v3 4/5] sysctl: simplify unsigned int support Luis R. Rodriguez
2017-05-19 3:35 ` [PATCH v3 5/5] sysctl: add unsigned int range support Luis R. Rodriguez
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=20170516222511.GH17314@wotan.suse.de \
--to=mcgrof@kernel.org \
--cc=acme@redhat.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=bp@suse.de \
--cc=davem@davemloft.net \
--cc=deepa.kernel@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=ebiederm@xmission.com \
--cc=jeyu@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=matt@codeblueprint.co.uk \
--cc=mgorman@suse.de \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=rusty@rustcorp.com.au \
--cc=shuah@kernel.org \
--cc=subashab@codeaurora.org \
--cc=swhiteho@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=xypron.glpk@gmx.de \
/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
all inboxes | Powered by JetHome®