All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Sasha Levin <sashal@kernel.org>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	mhiramat@kernel.org, mingo@redhat.com, acme@kernel.org,
	namhyung@kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-perf-users@vger.kernel.org
Subject: Re: [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot()
Date: Sun, 24 Nov 2024 14:13:57 +0100	[thread overview]
Message-ID: <20241124131357.GA28360@redhat.com> (raw)
In-Reply-To: <20241124124623.3337983-1-sashal@kernel.org>

Hi Sasha,

but why do you think it makes sense to backport these "uprobes" cleanups?

Oleg.

On 11/24, Sasha Levin wrote:
>
> From: Oleg Nesterov <oleg@redhat.com>
>
> [ Upstream commit c7b4133c48445dde789ed30b19ccb0448c7593f7 ]
>
> 1. Clear utask->xol_vaddr unconditionally, even if this addr is not valid,
>    xol_free_insn_slot() should never return with utask->xol_vaddr != NULL.
>
> 2. Add a comment to explain why do we need to validate slot_addr.
>
> 3. Simplify the validation above. We can simply check offset < PAGE_SIZE,
>    unsigned underflows are fine, it should work if slot_addr < area->vaddr.
>
> 4. Kill the unnecessary "slot_nr >= UINSNS_PER_PAGE" check, slot_nr must
>    be valid if offset < PAGE_SIZE.
>
> The next patches will cleanup this function even more.
>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Link: https://lore.kernel.org/r/20240929144235.GA9471@redhat.com
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
>  kernel/events/uprobes.c | 21 +++++++++------------
>  1 file changed, 9 insertions(+), 12 deletions(-)
>
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 4b52cb2ae6d62..cc605df73d72f 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1683,8 +1683,8 @@ static unsigned long xol_get_insn_slot(struct uprobe *uprobe)
>  static void xol_free_insn_slot(struct task_struct *tsk)
>  {
>  	struct xol_area *area;
> -	unsigned long vma_end;
>  	unsigned long slot_addr;
> +	unsigned long offset;
>
>  	if (!tsk->mm || !tsk->mm->uprobes_state.xol_area || !tsk->utask)
>  		return;
> @@ -1693,24 +1693,21 @@ static void xol_free_insn_slot(struct task_struct *tsk)
>  	if (unlikely(!slot_addr))
>  		return;
>
> +	tsk->utask->xol_vaddr = 0;
>  	area = tsk->mm->uprobes_state.xol_area;
> -	vma_end = area->vaddr + PAGE_SIZE;
> -	if (area->vaddr <= slot_addr && slot_addr < vma_end) {
> -		unsigned long offset;
> -		int slot_nr;
> -
> -		offset = slot_addr - area->vaddr;
> -		slot_nr = offset / UPROBE_XOL_SLOT_BYTES;
> -		if (slot_nr >= UINSNS_PER_PAGE)
> -			return;
> +	offset = slot_addr - area->vaddr;
> +	/*
> +	 * slot_addr must fit into [area->vaddr, area->vaddr + PAGE_SIZE).
> +	 * This check can only fail if the "[uprobes]" vma was mremap'ed.
> +	 */
> +	if (offset < PAGE_SIZE) {
> +		int slot_nr = offset / UPROBE_XOL_SLOT_BYTES;
>
>  		clear_bit(slot_nr, area->bitmap);
>  		atomic_dec(&area->slot_count);
>  		smp_mb__after_atomic(); /* pairs with prepare_to_wait() */
>  		if (waitqueue_active(&area->wq))
>  			wake_up(&area->wq);
> -
> -		tsk->utask->xol_vaddr = 0;
>  	}
>  }
>
> --
> 2.43.0
>


  parent reply	other threads:[~2024-11-24 13:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-24 12:46 [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot() Sasha Levin
2024-11-24 12:46 ` [PATCH AUTOSEL 6.12 2/5] perf/x86/amd: Warn only on new bits set Sasha Levin
2024-11-24 12:46 ` [PATCH AUTOSEL 6.12 3/5] locking/ww_mutex: Adjust to lockdep nest_lock requirements Sasha Levin
2024-11-25 10:06   ` Thomas Hellström
2024-11-25 13:34     ` Sasha Levin
2024-11-24 12:46 ` [PATCH AUTOSEL 6.12 4/5] cleanup: Adjust scoped_guard() macros to avoid potential warning Sasha Levin
2024-11-24 12:46 ` [PATCH AUTOSEL 6.12 5/5] timekeeping: Always check for negative motion Sasha Levin
2024-11-24 13:13 ` Oleg Nesterov [this message]
2024-11-24 14:15   ` [PATCH AUTOSEL 6.12 1/5] uprobes: sanitiize xol_free_insn_slot() Sasha Levin
2024-11-24 14:36     ` Oleg Nesterov

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=20241124131357.GA28360@redhat.com \
    --to=oleg@redhat.com \
    --cc=acme@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.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.