[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202403040940.BAFD26EA4@keescook>
Date: Mon, 4 Mar 2024 09:42:00 -0800
From: Kees Cook <keescook@...omium.org>
To: Adrian Ratiu <adrian.ratiu@...labora.com>
Cc: linux-fsdevel@...r.kernel.org, kernel@...labora.com,
linux-security-module@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org, linux-doc@...r.kernel.org,
Guenter Roeck <groeck@...omium.org>,
Doug Anderson <dianders@...omium.org>, Jann Horn <jannh@...gle.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Randy Dunlap <rdunlap@...radead.org>,
Christian Brauner <brauner@...nel.org>,
Mike Frysinger <vapier@...omium.org>
Subject: Re: [PATCH v2] proc: allow restricting /proc/pid/mem writes
On Mon, Mar 04, 2024 at 02:06:43PM +0000, Adrian Ratiu wrote:
> On Saturday, March 02, 2024 01:55 EET, Kees Cook <keescook@...omium.org> wrote:
> > On Fri, Mar 01, 2024 at 11:34:42PM +0200, Adrian Ratiu wrote:
> > > [...]
> > > +# define PROC_PID_MEM_MODE S_IRUSR
> > > +#else
> > > +# define PROC_PID_MEM_MODE (S_IRUSR|S_IWUSR)
> > > +#endif
> >
> > PROC_PID_MEM_MODE will need to be a __ro_after_init variable, set by
> > early_restrict_proc_mem_write, otherwise the mode won't change based on
> > the runtime setting. e.g.:
> >
> > #ifdef CONFIG_SECURITY_PROC_MEM_RESTRICT_WRITE_DEFAULT_ON
> > mode_t proc_pid_mem_mode __ro_after_init = S_IRUSR;
> > #else
> > mode_t proc_pid_mem_mode __ro_after_init = (S_IRUSR|S_IWUSR);
> > #endif
> >
> > DEFINE_STATIC_KEY_MAYBE_RO(CONFIG_SECURITY_PROC_MEM_RESTRICT_WRITE_DEFAULT_ON,
> > restrict_proc_mem_write);
> > ...
> > if (bool_result) {
> > static_branch_enable(&restrict_proc_mem_write);
> > proc_pid_mem_mode = S_IRUSR;
> > } else {
> > static_branch_disable(&restrict_proc_mem_write);
> > proc_pid_mem_mode = (S_IRUSR|S_IWUSR);
> > }
> > ...
> > REG("mem", proc_pid_mem_mode, proc_mem_operations),
>
> I'm having trouble implementing this because the proc_pid_mem_mode initializer needs to be a compile-time constant, so I can't set a runtime value in the REG() definition like suggested above.
Ah. Yeah, so I guess just drop the perms change -- you're already
checking the behavior in the open(), so you can just leave the perms
alone.
--
Kees Cook
Powered by blists - more mailing lists