From: Kees Cook <keescook@chromium.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matthew Wilcox <willy@infradead.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux-MM <linux-mm@kvack.org>, Jordy Zomer <jordy@pwning.systems>,
James Bottomley <James.Bottomley@hansenpartnership.com>,
Mike Rapoport <rppt@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] secretmem: Prevent secretmem_users from wrapping to zero
Date: Mon, 25 Oct 2021 17:17:57 -0700 [thread overview]
Message-ID: <202110251706.BBEE1428@keescook> (raw)
In-Reply-To: <CAHk-=wj9j8KnWzTTFCXi_xWyytFbtZ71hu32eB=nHR++X+UY=A@mail.gmail.com>
On Mon, Oct 25, 2021 at 04:37:01PM -0700, Linus Torvalds wrote:
> If we want other semantics, it should be a new type.
Okay, that's reasonable.
> > I see that is more like a "shared resource usage count" where the shared
> > resource doesn't necessarily disappear when we reach "no users"?
>
> So I think that's really "atomic_t".
>
> And instead of saturating, people should always check such shared
> resources for limits.
Right, but people make mistakes, etc. I agree about the limit being much
more sane than saturating (though in the cases of "missed decrement"),
we get to the same place: an open-coded check for the limit that never
goes down doesn't matter if it's refcount_t nor atomic_t. :)
> > i.e. there is some resource, and it starts its life with no one using it
> > (count = 1).
>
> You are already going off into the weeds.
>
> That's not a natural thing to do. It's already confusing. Really. Read
> that sentence yourself, and read it like an outsider.
>
> "No one is using it, so count == 1" is a nonsensican statement on the
> face of it.
>
> You are thinking of a refcount_t trick, not some sane semantics.
>
> Yes, we have played off-by-one games in the kernel before. We've done
> it for various subtle reasons.
Right, sure, but it's not a rare pattern. Given that it exists, and that
it _does_ get used for allocation management (e.g. module loader), it
seems worth constructing a proper type for it so that all the open coded
stuff around these instances can be consolidated, and the API can be
defined in a way that will behave sanely.
> I really don't see what's wrong with 'atomic_t', and just checking for limits.
It's that last part. :) If we go through atomic_dec() see a zero and do
something, okay, fine. But these places need to check for insane
conditions too ("we got a -1 back -- this means there's a bug but what
do we do?"). Same for atomic_inc(): "oh, we're at our limit, do
something", but what above discovering ourselves above the limit?
There's nothing about using the atomic_t primitives that enforces these
kinds of checks. (And there likely shouldn't be for atomic_t -- it's a
plain type.) But we likely need something that fills in this API gap
between atomic_t and refcount_t.
> So if a user can ever trigger a saturating counter, that's a big big
> problem in itself.
Yes! It is. :) But they don't get to gain control over a Use-after-Free.
The risk to the system is DoS instead of loss of execution control.
That's a meaningful risk downgrade.
So, what's the right semantics for an atomic type that could be used in
the module loader, that would catch kernel counting bugs in a safe manner?
The "refcount_t but 1-based" is close, but clearly not the right name. :)
--
Kees Cook
next prev parent reply other threads:[~2021-10-26 0:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-25 18:16 [PATCH] secretmem: Prevent secretmem_users from wrapping to zero Matthew Wilcox (Oracle)
2021-10-25 19:29 ` Kees Cook
2021-10-25 19:51 ` Matthew Wilcox
2021-10-25 21:04 ` Kees Cook
2021-10-25 21:17 ` Linus Torvalds
2021-10-25 22:30 ` Kees Cook
2021-10-25 23:37 ` Linus Torvalds
2021-10-26 0:02 ` Linus Torvalds
2021-10-26 0:17 ` Kees Cook [this message]
2021-10-26 1:10 ` Linus Torvalds
2021-10-26 1:34 ` Matthew Wilcox
2021-10-31 1:42 ` kernel test robot
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=202110251706.BBEE1428@keescook \
--to=keescook@chromium.org \
--cc=James.Bottomley@hansenpartnership.com \
--cc=akpm@linux-foundation.org \
--cc=jordy@pwning.systems \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rppt@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=willy@infradead.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 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.