All of lore.kernel.org
 help / color / mirror / Atom feed
From: "tip-bot2 for Waiman Long" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Marco Elver <elver@google.com>, Waiman Long <longman@redhat.com>,
	Andrey Konovalov <andreyknvl@gmail.com>,
	Boqun Feng <boqun.feng@gmail.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: locking/core] locking/lockdep: Add kasan_check_byte() check in lock_acquire()
Date: Mon, 03 Mar 2025 18:51:56 -0000	[thread overview]
Message-ID: <174102791660.14745.9286305165627700375.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20250214195242.2480920-1-longman@redhat.com>

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

Commit-ID:     8ca5e9186d367807336c5a40a086aef163c18800
Gitweb:        https://git.kernel.org/tip/8ca5e9186d367807336c5a40a086aef163c18800
Author:        Waiman Long <longman@redhat.com>
AuthorDate:    Fri, 14 Feb 2025 14:52:42 -05:00
Committer:     Boqun Feng <boqun.feng@gmail.com>
CommitterDate: Sun, 23 Feb 2025 18:24:46 -08:00

locking/lockdep: Add kasan_check_byte() check in lock_acquire()

KASAN instrumentation of lockdep has been disabled as we don't need
KASAN to check the validity of lockdep internal data structures and
incur unnecessary performance overhead. However, the lockdep_map pointer
passed in externally may not be valid (e.g. use-after-free) and we run
the risk of using garbage data resulting in false lockdep reports.

Add kasan_check_byte() call in lock_acquire() for non kernel core data
object to catch invalid lockdep_map and print out a KASAN report before
any lockdep splat, if any.

Suggested-by: Marco Elver <elver@google.com>
Signed-off-by: Waiman Long <longman@redhat.com>
Reviewed-by: Marco Elver <elver@google.com>
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250214195242.2480920-1-longman@redhat.com
---
 kernel/locking/lockdep.c |  9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 8436f01..b15757e 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -57,6 +57,7 @@
 #include <linux/lockdep.h>
 #include <linux/context_tracking.h>
 #include <linux/console.h>
+#include <linux/kasan.h>
 
 #include <asm/sections.h>
 
@@ -5830,6 +5831,14 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
 	if (!debug_locks)
 		return;
 
+	/*
+	 * As KASAN instrumentation is disabled and lock_acquire() is usually
+	 * the first lockdep call when a task tries to acquire a lock, add
+	 * kasan_check_byte() here to check for use-after-free and other
+	 * memory errors.
+	 */
+	kasan_check_byte(lock);
+
 	if (unlikely(!lockdep_enabled())) {
 		/* XXX allow trylock from NMI ?!? */
 		if (lockdep_nmi() && !trylock) {

  parent reply	other threads:[~2025-03-03 18:52 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-13 20:02 [PATCH v4 0/4] locking/lockdep: Disable KASAN instrumentation of lockdep.c Waiman Long
2025-02-13 20:02 ` [PATCH v4 1/4] locking/lock_events: Add locking events for rtmutex slow paths Waiman Long
2025-03-03 18:51   ` [tip: locking/core] " tip-bot2 for Waiman Long
2025-02-13 20:02 ` [PATCH v4 2/4] locking/lock_events: Add locking events for lockdep Waiman Long
2025-03-03 18:51   ` [tip: locking/core] " tip-bot2 for Waiman Long
2025-02-13 20:02 ` [PATCH v4 3/4] locking/lockdep: Disable KASAN instrumentation of lockdep.c Waiman Long
2025-02-17  7:00   ` Marco Elver
2025-02-17 16:53   ` Andrey Konovalov
2025-03-03 18:51   ` [tip: locking/core] " tip-bot2 for Waiman Long
2025-02-13 20:02 ` [PATCH v4 4/4] locking/lockdep: Add kasan_check_byte() check in lock_acquire() Waiman Long
2025-02-14 10:44   ` Marco Elver
2025-02-14 14:09     ` Waiman Long
2025-02-14 14:44       ` Marco Elver
2025-02-14 15:30         ` Waiman Long
2025-02-14 16:18         ` Waiman Long
2025-02-14 16:43           ` Marco Elver
2025-02-14 17:18             ` Waiman Long
2025-02-14 19:52 ` [PATCH v4.1 " Waiman Long
2025-02-17  7:00   ` Marco Elver
2025-02-17 16:51   ` Andrey Konovalov
2025-03-03 18:51   ` tip-bot2 for Waiman Long [this message]
2025-02-24  2:11 ` [PATCH v4 0/4] locking/lockdep: Disable KASAN instrumentation of lockdep.c Boqun Feng
  -- strict thread matches above, loose matches on Subject: below --
2025-03-07 23:26 [PATCH locking 06/11] locking/lockdep: Add kasan_check_byte() check in lock_acquire() Boqun Feng
2025-03-08  0:08 ` [tip: locking/core] " tip-bot2 for Waiman Long

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=174102791660.14745.9286305165627700375.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=andreyknvl@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=elver@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=longman@redhat.com \
    --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 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.