From: "Adrian Ratiu" <adrian.ratiu@collabora.com>
To: "Linus Torvalds" <torvalds@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
kernel@collabora.com, gbiv@google.com, inglorion@google.com,
ajordanr@google.com, "Doug Anderson" <dianders@chromium.org>,
"Jeff Xu" <jeffxu@google.com>, "Jann Horn" <jannh@google.com>,
"Kees Cook" <kees@kernel.org>,
"Christian Brauner" <brauner@kernel.org>
Subject: Re: [PATCH] proc: add config & param to block forcing mem writes
Date: Wed, 24 Jul 2024 10:16:25 +0100 [thread overview]
Message-ID: <27ea5-66a0c680-3-322bfd00@171174474> (raw)
In-Reply-To: <CAHk-=wiJL59WxvyHOuz2ChW+Vi1PTRKJ+w+9E8d1f4QZs9UFcg@mail.gmail.com>
On Tuesday, July 23, 2024 21:30 EEST, Linus Torvalds <torvalds@linux-foundation.org> wrote:
> On Tue, 23 Jul 2024 at 10:18, Adrian Ratiu <adrian.ratiu@collabora.com> wrote:
> >
> > This adds a Kconfig option and boot param to allow removing
> > the FOLL_FORCE flag from /proc/pid/mem write calls because
> > it can be abused.
>
> Ack, this looks much simpler.
>
> That said, I think this can be prettied up some more:
>
> > +enum proc_mem_force_state {
> > + PROC_MEM_FORCE_ALWAYS,
> > + PROC_MEM_FORCE_PTRACE,
> > + PROC_MEM_FORCE_NEVER
> > +};
> > +
> > +#if defined(CONFIG_PROC_MEM_ALWAYS_FORCE)
> > +static enum proc_mem_force_state proc_mem_force_override __ro_after_init = PROC_MEM_FORCE_ALWAYS;
> > +#elif defined(CONFIG_PROC_MEM_FORCE_PTRACE)
> > +static enum proc_mem_force_state proc_mem_force_override __ro_after_init = PROC_MEM_FORCE_PTRACE;
> > +#else
> > +static enum proc_mem_force_state proc_mem_force_override __ro_after_init = PROC_MEM_FORCE_NEVER;
> > +#endif
>
> I think instead of that forest of #if defined(), we can just do
>
> enum proc_mem_force {
> PROC_MEM_FORCE_ALWAYS,
> PROC_MEM_FORCE_PTRACE,
> PROC_MEM_FORCE_NEVER
> };
>
> static enum proc_mem_force proc_mem_force_override __ro_after_init =
> IS_ENABLED(CONFIG_PROC_MEM_ALWAYS_FORCE) ? PROC_MEM_FORCE_ALWAYS :
> IS_ENABLED(CONFIG_PROC_MEM_FORCE_PTRACE) ? PROC_MEM_FORCE_PTRACE :
> PROC_MEM_FORCE_NEVER;
>
> I also really thought we had some parser helper for this pattern:
>
> > +static int __init early_proc_mem_force_override(char *buf)
> > +{
> > + if (!buf)
> > + return -EINVAL;
> > +
> > + if (strcmp(buf, "always") == 0) {
> > + proc_mem_force_override = PROC_MEM_FORCE_ALWAYS;
> ....
>
> but it turns out we only really "officially" have it for filesystem
> superblock parsing.
>
> Oh well. We could do
>
> #include <linux/fs_parser.h>
> ...
> struct constant_table proc_mem_force_table[] {
> { "ptrace", PROC_MEM_FORCE_PTRACE },
> { "never", PROC_MEM_FORCE_NEVER },
> { }
> };
> ...
> proc_mem_force_override = lookup_constant(
> proc_mem_force_table, buf, PROC_MEM_FORCE_NEVER);
>
> but while that looks a bit prettier, the whole "fs_parser.h" thing is
> admittedly odd.
>
> Anyway, I think the patch is ok, although I also happen to think it
> could be a bit prettier.
Thanks again, I am perfectly fine with using fs_parser.h.
I'll wait a few days to give others a chance to review/respond,
then apply your changes and send a v3.
(this was actually v2, however git format-patch removed my
"Changes in v2" blurb and v2 title; will add them next time)
prev parent reply other threads:[~2024-07-24 9:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-23 17:17 [PATCH] proc: add config & param to block forcing mem writes Adrian Ratiu
2024-07-23 18:30 ` Linus Torvalds
2024-07-23 18:33 ` Linus Torvalds
2024-07-24 9:16 ` Adrian Ratiu [this message]
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=27ea5-66a0c680-3-322bfd00@171174474 \
--to=adrian.ratiu@collabora.com \
--cc=ajordanr@google.com \
--cc=brauner@kernel.org \
--cc=dianders@chromium.org \
--cc=gbiv@google.com \
--cc=inglorion@google.com \
--cc=jannh@google.com \
--cc=jeffxu@google.com \
--cc=kees@kernel.org \
--cc=kernel@collabora.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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).