From: Kees Cook <keescook@chromium.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Borislav Petkov <bp@alien8.de>,
Xiyu Yang <xiyuyang19@fudan.edu.cn>,
Alistair Popple <apopple@nvidia.com>,
Yang Shi <shy828301@gmail.com>,
Shakeel Butt <shakeelb@google.com>,
Hugh Dickins <hughd@google.com>,
Miaohe Lin <linmiaohe@huawei.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux-MM <linux-mm@kvack.org>,
yuanxzhang@fudan.edu.cn, Xin Tan <tanxin.ctf@gmail.com>,
Will Deacon <will.deacon@arm.com>,
David Howells <dhowells@redhat.com>
Subject: Re: [PATCH] mm/rmap: Convert from atomic_t to refcount_t on anon_vma->refcount
Date: Fri, 20 Aug 2021 10:26:10 -0700 [thread overview]
Message-ID: <202108201013.36752C28@keescook> (raw)
In-Reply-To: <YR9vxHlSFalryHi0@hirez.programming.kicks-ass.net>
On Fri, Aug 20, 2021 at 11:03:00AM +0200, Peter Zijlstra wrote:
> On Fri, Aug 20, 2021 at 09:24:58AM +0100, Will Deacon wrote:
>
> > > gcc-10.2.1, x86_64-defconfig
> > >
> > > kernel/event/core.o-inline-ud1: 96454
> > > kernel/event/core.o-outofline-ud1: 96604
> > > kernel/event/core.o-outofline-call: 97072
>
> kernel/event/core.o-outofline-saturate-ud2: 96954
> kernel/event/core.o: 97248
>
> > Is that with the saturation moved to the UD handler as well?
>
> Yep, that's the full function call replaced with an exception.
>
> > I think it would be good to keep that as close to the point at which
> > we detect the problem as we can, so perhaps we can inline that part
> > and leave the diagnostics to the exception handler?
>
> That's simpler execption code too, we can abuse the existing WARN/UD2
> stuff.
>
> ---
> arch/x86/include/asm/refcount.h | 31 +++++++++++++++++++++++++++++++
> include/asm-generic/bug.h | 4 ++++
> include/linux/refcount.h | 15 +++++++++++----
> lib/bug.c | 13 ++++++++++++-
> lib/refcount.c | 7 ++-----
> 5 files changed, 60 insertions(+), 10 deletions(-)
>
> diff --git a/arch/x86/include/asm/refcount.h b/arch/x86/include/asm/refcount.h
> new file mode 100644
> index 000000000000..bed52b95d24c
> --- /dev/null
> +++ b/arch/x86/include/asm/refcount.h
> @@ -0,0 +1,31 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _ASM_X86_REFCOUNT_H
> +#define _ASM_X86_REFCOUNT_H
> +
> +#define refcount_warn_saturate refcount_warn_saturate
> +static __always_inline void refcount_warn_saturate(refcount_t *r, const enum refcount_saturation_type t)
> +{
> + refcount_set(r, REFCOUNT_SATURATED);
> + __WARN_FLAGS(BUGFLAG_ONCE|BUGFLAG_REFCOUNT|BUGFLAG_REFCOUNT_TYPE(t));
> +}
Instead of using up warn flags, what was done in
the past was to use an explicit EXTABLE in a cold text section:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/include/asm/asm.h?h=v4.15#n80
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/mm/extable.c?h=v4.15#n45
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/include/asm/refcount.h?h=v4.15
> +
> +#define refcount_dec_and_test refcount_dec_and_test
> +static inline bool refcount_dec_and_test(refcount_t *r)
> +{
> + asm_volatile_goto (LOCK_PREFIX "decl %[var]\n\t"
> + "jz %l[cc_zero]\n\t"
> + "jl %l[cc_error]"
> + : : [var] "m" (r->refs.counter)
> + : "memory" : cc_zero, cc_error);
> +
> + return false;
> +
> +cc_zero:
> + return true;
> +
> +cc_error:
> + refcount_warn_saturate(r, REFCOUNT_SUB_UAF);
> + return false;
> +}
This looks basically the same as what we had before (i.e. the earlier
REFCOUNT_CHECK_LE_ZERO within GEN_UNARY_SUFFIXED_RMWcc).
--
Kees Cook
prev parent reply other threads:[~2021-08-20 17:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-19 3:23 [PATCH] mm/rmap: Convert from atomic_t to refcount_t on anon_vma->refcount Xiyu Yang
2021-07-20 23:01 ` Andrew Morton
2021-08-19 13:21 ` Will Deacon
2021-08-19 14:06 ` Peter Zijlstra
2021-08-19 15:19 ` Peter Zijlstra
2021-08-19 19:09 ` Linus Torvalds
2021-08-20 6:43 ` Peter Zijlstra
2021-08-20 7:33 ` Kees Cook
2021-08-20 8:16 ` Peter Zijlstra
2021-08-20 8:24 ` Will Deacon
2021-08-20 9:03 ` Peter Zijlstra
2021-08-20 17:26 ` Kees Cook [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=202108201013.36752C28@keescook \
--to=keescook@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=bp@alien8.de \
--cc=dhowells@redhat.com \
--cc=hughd@google.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterz@infradead.org \
--cc=shakeelb@google.com \
--cc=shy828301@gmail.com \
--cc=tanxin.ctf@gmail.com \
--cc=torvalds@linux-foundation.org \
--cc=will.deacon@arm.com \
--cc=will@kernel.org \
--cc=xiyuyang19@fudan.edu.cn \
--cc=yuanxzhang@fudan.edu.cn \
/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).