linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	"H. Peter Anvin" <hpa@zytor.com>, Paul Turner <pjt@google.com>,
	linux-api <linux-api@vger.kernel.org>,
	Peter Oskolkov <posk@posk.io>
Subject: Re: [PATCH 2/2] rseq: Kill process when unknown flags are encountered in ABI structures
Date: Mon, 1 Aug 2022 10:42:45 -0400 (EDT)	[thread overview]
Message-ID: <1656318880.93523.1659364965914.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <87tu6wm46t.fsf@oldenburg.str.redhat.com>

----- On Aug 1, 2022, at 10:25 AM, Florian Weimer fweimer@redhat.com wrote:

> * Ingo Molnar:
> 
>> * Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote:
>>
>>> rseq_abi()->flags and rseq_abi()->rseq_cs->flags 29 upper bits are
>>> currently unused.
>>> 
>>> The current behavior when those bits are set is to ignore them. This is
>>> not an ideal behavior, because when future features will start using
>>> those flags, if user-space fails to correctly validate that the kernel
>>> indeed supports those flags (e.g. with a new sys_rseq flags bit) before
>>> using them, it may incorrectly assume that the kernel will handle those
>>> flags way when in fact those will be silently ignored on older kernels.
>>> 
>>> Validating that unused flags bits are cleared will allow a smoother
>>> transition when those flags will start to be used by allowing
>>> applications to fail early, and obviously, when they attempt to use the
>>> new flags on an older kernel that does not support them.
>>> 
>>> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
>>> ---
>>>  kernel/rseq.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>> 
>>> diff --git a/kernel/rseq.c b/kernel/rseq.c
>>> index 81d7dc80787b..bda8175f8f99 100644
>>> --- a/kernel/rseq.c
>>> +++ b/kernel/rseq.c
>>> @@ -176,7 +176,7 @@ static int rseq_need_restart(struct task_struct *t, u32
>>> cs_flags)
>>>  	u32 flags, event_mask;
>>>  	int ret;
>>>  
>>> -	if (WARN_ON_ONCE(cs_flags & RSEQ_CS_NO_RESTART_FLAGS))
>>> +	if (WARN_ON_ONCE(cs_flags & RSEQ_CS_NO_RESTART_FLAGS) || cs_flags)
>>>  		return -EINVAL;
>>>  
>>>  	/* Get thread flags. */
>>> @@ -184,7 +184,7 @@ static int rseq_need_restart(struct task_struct *t, u32
>>> cs_flags)
>>>  	if (ret)
>>>  		return ret;
>>>  
>>> -	if (WARN_ON_ONCE(flags & RSEQ_CS_NO_RESTART_FLAGS))
>>> +	if (WARN_ON_ONCE(flags & RSEQ_CS_NO_RESTART_FLAGS) || flags)
>>>  		return -EINVAL;
>>
>> Just to make it clear: no existing libraries/tooling out there have learned
>> to rely on the old ABI that ignored unset flags, right? Only then is this
>> patch ABI-safe.
> 
> I believe glibc initializes the flag fields to zero before calling the
> rseq system call.  (I don't know if the rseq system call does its own
> initialization; maybe it should if it doesn't do so already.)

Initialization and following updates of rseq_abi()->flags and
rseq_abi()->rseq_cs->flags is done by user-space, so the rseq
system call does not initialize any of those fields.

Indeed glibc initialize the rseq_abi()->flags to 0, and does not
use rseq_abi()->rseq_cs->flags as of now.

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

  reply	other threads:[~2022-08-01 14:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-22 19:46 [PATCH 1/2] rseq: Deprecate RSEQ_CS_FLAG_NO_RESTART_ON_* flags Mathieu Desnoyers
2022-06-22 19:46 ` [PATCH 2/2] rseq: Kill process when unknown flags are encountered in ABI structures Mathieu Desnoyers
2022-07-26 19:11   ` Mathieu Desnoyers
2022-08-01 13:32   ` Ingo Molnar
2022-08-01 14:25     ` Florian Weimer
2022-08-01 14:42       ` Mathieu Desnoyers [this message]
2022-08-01 14:39     ` Mathieu Desnoyers
2022-08-01 19:40       ` Ingo Molnar
2022-07-26 19:10 ` [PATCH 1/2] rseq: Deprecate RSEQ_CS_FLAG_NO_RESTART_ON_* flags Mathieu Desnoyers

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=1656318880.93523.1659364965914.JavaMail.zimbra@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=boqun.feng@gmail.com \
    --cc=fweimer@redhat.com \
    --cc=hpa@zytor.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=posk@posk.io \
    --cc=tglx@linutronix.de \
    /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).