mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for André Rösti" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: an.roesti@gmail.com, Thomas Gleixner <tglx@linutronix.de>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: core/entry] entry: Respect changes to system call number by trace_sys_enter()
Date: Tue, 12 Mar 2024 12:31:33 -0000	[thread overview]
Message-ID: <171024669388.398.6202671416393382328.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20240311211704.7262-1-an.roesti@gmail.com>

The following commit has been merged into the core/entry branch of tip:

Commit-ID:     fb13b11d53875e28e7fbf0c26b288e4ea676aa9f
Gitweb:        https://git.kernel.org/tip/fb13b11d53875e28e7fbf0c26b288e4ea676aa9f
Author:        André Rösti <an.roesti@gmail.com>
AuthorDate:    Mon, 11 Mar 2024 21:17:04 
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Tue, 12 Mar 2024 13:23:32 +01:00

entry: Respect changes to system call number by trace_sys_enter()

When a probe is registered at the trace_sys_enter() tracepoint, and that
probe changes the system call number, the old system call still gets
executed.  This worked correctly until commit b6ec41346103 ("core/entry:
Report syscall correctly for trace and audit"), which removed the
re-evaluation of the syscall number after the trace point.

Restore the original semantics by re-evaluating the system call number
after trace_sys_enter(). 

The performance impact of this re-evaluation is minimal because it only
takes place when a trace point is active, and compared to the actual trace
point overhead the read from a cache hot variable is negligible.

Fixes: b6ec41346103 ("core/entry: Report syscall correctly for trace and audit")
Signed-off-by: André Rösti <an.roesti@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240311211704.7262-1-an.roesti@gmail.com
---
 kernel/entry/common.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/entry/common.c b/kernel/entry/common.c
index 88cb3c8..90843cc 100644
--- a/kernel/entry/common.c
+++ b/kernel/entry/common.c
@@ -57,8 +57,14 @@ long syscall_trace_enter(struct pt_regs *regs, long syscall,
 	/* Either of the above might have changed the syscall number */
 	syscall = syscall_get_nr(current, regs);
 
-	if (unlikely(work & SYSCALL_WORK_SYSCALL_TRACEPOINT))
+	if (unlikely(work & SYSCALL_WORK_SYSCALL_TRACEPOINT)) {
 		trace_sys_enter(regs, syscall);
+		/*
+		 * Probes or BPF hooks in the tracepoint may have changed the
+		 * system call number as well.
+		 */
+		syscall = syscall_get_nr(current, regs);
+	}
 
 	syscall_enter_audit(regs, syscall);
 

      reply	other threads:[~2024-03-12 12:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11 21:17 [PATCH v2] entry: Respect changes to system call number at sys_enter tracepoint André Rösti
2024-03-12 12:31 ` tip-bot2 for André Rösti [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=171024669388.398.6202671416393382328.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=an.roesti@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®