Patch "kcsan, seqlock: Fix incorrect assumption in read_seqbegin()" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    kcsan, seqlock: Fix incorrect assumption in read_seqbegin()

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     kcsan-seqlock-fix-incorrect-assumption-in-read_seqbe.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit cb70b82254c5f50467b87e75c1ad05f830dd29dc
Author: Marco Elver <elver@xxxxxxxxxx>
Date:   Mon Nov 4 16:43:09 2024 +0100

    kcsan, seqlock: Fix incorrect assumption in read_seqbegin()
    
    [ Upstream commit 183ec5f26b2fc97a4a9871865bfe9b33c41fddb2 ]
    
    During testing of the preceding changes, I noticed that in some cases,
    current->kcsan_ctx.in_flat_atomic remained true until task exit. This is
    obviously wrong, because _all_ accesses for the given task will be
    treated as atomic, resulting in false negatives i.e. missed data races.
    
    Debugging led to fs/dcache.c, where we can see this usage of seqlock:
    
            struct dentry *d_lookup(const struct dentry *parent, const struct qstr *name)
            {
                    struct dentry *dentry;
                    unsigned seq;
    
                    do {
                            seq = read_seqbegin(&rename_lock);
                            dentry = __d_lookup(parent, name);
                            if (dentry)
                                    break;
                    } while (read_seqretry(&rename_lock, seq));
            [...]
    
    As can be seen, read_seqretry() is never called if dentry != NULL;
    consequently, current->kcsan_ctx.in_flat_atomic will never be reset to
    false by read_seqretry().
    
    Give up on the wrong assumption of "assume closing read_seqretry()", and
    rely on the already-present annotations in read_seqcount_begin/retry().
    
    Fixes: 88ecd153be95 ("seqlock, kcsan: Add annotations for KCSAN")
    Signed-off-by: Marco Elver <elver@xxxxxxxxxx>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20241104161910.780003-6-elver@xxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
index a06af404c4b2a..49943cad85fe7 100644
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -894,11 +894,7 @@ typedef struct {
  */
 static inline unsigned read_seqbegin(const seqlock_t *sl)
 {
-	unsigned ret = read_seqcount_begin(&sl->seqcount);
-
-	kcsan_atomic_next(0);  /* non-raw usage, assume closing read_seqretry() */
-	kcsan_flat_atomic_begin();
-	return ret;
+	return read_seqcount_begin(&sl->seqcount);
 }
 
 /**
@@ -914,12 +910,6 @@ static inline unsigned read_seqbegin(const seqlock_t *sl)
  */
 static inline unsigned read_seqretry(const seqlock_t *sl, unsigned start)
 {
-	/*
-	 * Assume not nested: read_seqretry() may be called multiple times when
-	 * completing read critical section.
-	 */
-	kcsan_flat_atomic_end();
-
 	return read_seqcount_retry(&sl->seqcount, start);
 }
 




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux