All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: "Paul Moore" <paul@paul-moore.com>,
	"Fan Wu" <wufan@linux.microsoft.com>,
	"Mickaël Salaün" <mic@digikod.net>,
	"Mimi Zohar" <zohar@linux.ibm.com>,
	"Micah Morton" <mortonm@chromium.org>,
	"Casey Schaufler" <casey@schaufler-ca.com>,
	"John Johansen" <john.johansen@canonical.com>,
	"Roberto Sassu" <roberto.sassu@huawei.com>,
	"KP Singh" <kpsingh@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	linux-security-module@vger.kernel.org
Subject: Re: TOMOYO's pull request for v6.12
Date: Fri, 4 Oct 2024 17:17:08 -0700	[thread overview]
Message-ID: <202410041645.27A48DA@keescook> (raw)
In-Reply-To: <ece0c7bd-0d28-4562-8760-c54b0077583a@I-love.SAKURA.ne.jp>

On Sat, Oct 05, 2024 at 08:41:06AM +0900, Tetsuo Handa wrote:
> On 2024/10/05 5:54, Kees Cook wrote:
> > - tomoyo_register_hooks() becomes an exploitation gadget that could be
> >   used to bypass the LSM as a whole.
> 
> tomoyo_register_hooks() is enabled only if "CONFIG_SECURITY_TOMOYO_LKM is
> included while building the kernel" && "security=tomoyo is specified or
> tomoyo is included in the lsm= kernel command line options".
> 
> Therefore, those who are building kernels with CONFIG_SECURITY_TOMOYO_LKM=n are
> not affected.

Sure, but my point is that convincing RedHat that this is acceptable is
likely to be an uphill battle considering their effort to gain full
ro_after_init coverage for SELinux.

> Even if kernels are built with CONFIG_SECURITY_TOMOYO_LKM=y, callbacks
> registered by tomoyo_register_hooks() won't be called unless "security=tomoyo
> is specified or tomoyo is included in the lsm= kernel command line options", for
> the proxy callbacks that use static call tables are not registered.

This part I overlooked. I forgot that Tomoyo is still not fully stackable,
so it isn't getting included in CONFIG_LSM= for the distros that do
build it.

> Even if kernels are built with CONFIG_SECURITY_TOMOYO_LKM=y, and "security=tomoyo
> is specified or tomoyo is included in the lsm= kernel command line options",
> tomoyo_register_hooks() can be called only once.

An attacker with a read/write primitive would be able to locate and
write to "registered" (since it is not read-only), allowing them to call
tomoyo_register_hooks() multiple times.

> And tomoyo.ko is loaded by the
> time /sbin/init (nowadays /usr/lib/systemd/systemd) starts. That is, by the time
> an attacker can login from console or can start attacking via network,
> tomoyo_register_hooks() is no longer callable.

See above -- calling tomoyo_register_hooks() after boot is entirely
feasible given a read/write attack primitive.

> Therefore, the only problem with tomoyo.ko approach is that the static call tables
> for tomoyo_register_hooks() are currently not marked as __ro_after_init. But it will
> be possible to make the static call tables read-only if the static call tables

The tables actually don't matter as much -- an attacker could construct
their own table anywhere in kernel memory and pass that as an argument
for their call to tomoyo_register_hooks().

(This is actually one of the reasons I have pushed to have sensitive
functions like that be able to check that their passed-in argument is
contained in a read-only area, but that didn't get much traction[1].)

> are aligned in a page boundary and an architecture-dependent kernel API that changes
> given page's attribute to read-only is called. (This is why __ro_after_init can work,
> isn't it?)

The __ro_after_init section is immediately neighboring the .rodata
section, so when .rodata is marked read-only (after __init has
finished), the kernel marks both sections read-only. (Except for, I
think, s390, which does two passes: .rodata is read-only before __init,
and then __ro_after_init is marked read-only after __init.)

> As a whole, I don't think tomoyo.ko approach is unacceptably dangerous.

I agree, this implementation is safer than I initial assessed (due to the
LSM's view of the hooks being skipped due to lsm= not including tomoyo).
I still think how this patch ended up in Linus's tree was a big mistake,
though.

Regardless, my opinion is unchanged: I think it will be harder to convince
RedHat to build in _this_ version of tomoyo compared to the stock version.

(Out of curiosity, does RedHat build in AppArmor?)

-Kees

[1] https://lore.kernel.org/lkml/202408052100.74A2316C27@keescook/

-- 
Kees Cook

  reply	other threads:[~2024-10-05  0:17 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-02 20:12 TOMOYO's pull request for v6.12 Paul Moore
2024-10-03  2:43 ` Serge E. Hallyn
2024-10-03  2:51   ` Serge E. Hallyn
2024-10-03  3:05   ` John Johansen
2024-10-03 15:32   ` Paul Moore
2024-10-03 16:29     ` Serge E. Hallyn
2024-10-04 10:50       ` Tetsuo Handa
2024-10-04 13:11         ` Mickaël Salaün
2024-10-04 14:34           ` Tetsuo Handa
2024-10-05  4:39       ` John Johansen
2024-10-03 16:36 ` Casey Schaufler
2024-10-03 16:42   ` Serge E. Hallyn
2024-10-03 16:49     ` Paul Moore
2024-10-03 16:58     ` Casey Schaufler
2024-10-04 20:54 ` Kees Cook
2024-10-04 21:03   ` Paul Moore
2024-10-04 23:41   ` Tetsuo Handa
2024-10-05  0:17     ` Kees Cook [this message]
2024-10-05  3:38       ` John Johansen
2024-10-23 10:52         ` Tetsuo Handa
2024-10-05  7:10       ` Tetsuo Handa
2024-10-05 16:10         ` Casey Schaufler
2024-10-05 17:02           ` Dr. Greg
2024-10-05 18:58             ` Casey Schaufler
2024-10-05 23:47               ` Paul Moore
2024-10-06 16:18               ` Dr. Greg
2024-10-06 16:47                 ` Casey Schaufler
2024-10-06 20:20                 ` Paul Moore
2024-10-06 21:50                   ` John Johansen
2024-10-05 16:30         ` Paul Moore
2024-10-05 17:28           ` Simon Thoby
2024-10-06  0:02             ` Serge E. Hallyn
2024-10-06 10:02               ` Tetsuo Handa
2024-10-06 11:14                 ` Simon Thoby
2024-10-07 11:00                   ` Tetsuo Handa

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=202410041645.27A48DA@keescook \
    --to=kees@kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=corbet@lwn.net \
    --cc=john.johansen@canonical.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mic@digikod.net \
    --cc=mortonm@chromium.org \
    --cc=paul@paul-moore.com \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=roberto.sassu@huawei.com \
    --cc=wufan@linux.microsoft.com \
    --cc=zohar@linux.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.