Patch "bpf: Avoid uninitialized value in BPF_CORE_READ_BITFIELD" 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

    bpf: Avoid uninitialized value in BPF_CORE_READ_BITFIELD

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:
     bpf-avoid-uninitialized-value-in-bpf_core_read_bitfi.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 fd890a29bdf28db6c8e96d8c814e73a24bd69fb3
Author: Jose E. Marchesi <jose.marchesi@xxxxxxxxxx>
Date:   Wed May 8 12:13:13 2024 +0200

    bpf: Avoid uninitialized value in BPF_CORE_READ_BITFIELD
    
    [ Upstream commit 009367099eb61a4fc2af44d4eb06b6b4de7de6db ]
    
    [Changes from V1:
     - Use a default branch in the switch statement to initialize `val'.]
    
    GCC warns that `val' may be used uninitialized in the
    BPF_CRE_READ_BITFIELD macro, defined in bpf_core_read.h as:
    
            [...]
            unsigned long long val;                                               \
            [...]                                                                 \
            switch (__CORE_RELO(s, field, BYTE_SIZE)) {                           \
            case 1: val = *(const unsigned char *)p; break;                       \
            case 2: val = *(const unsigned short *)p; break;                      \
            case 4: val = *(const unsigned int *)p; break;                        \
            case 8: val = *(const unsigned long long *)p; break;                  \
            }                                                                     \
            [...]
            val;                                                                  \
            }                                                                     \
    
    This patch adds a default entry in the switch statement that sets
    `val' to zero in order to avoid the warning, and random values to be
    used in case __builtin_preserve_field_info returns unexpected values
    for BPF_FIELD_BYTE_SIZE.
    
    Tested in bpf-next master.
    No regressions.
    
    Signed-off-by: Jose E. Marchesi <jose.marchesi@xxxxxxxxxx>
    Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/20240508101313.16662-1-jose.marchesi@xxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/lib/bpf/bpf_core_read.h b/tools/lib/bpf/bpf_core_read.h
index e4aa9996a5501..b8e68a17f3f1b 100644
--- a/tools/lib/bpf/bpf_core_read.h
+++ b/tools/lib/bpf/bpf_core_read.h
@@ -101,6 +101,7 @@ enum bpf_enum_value_kind {
 	case 2: val = *(const unsigned short *)p; break;		      \
 	case 4: val = *(const unsigned int *)p; break;			      \
 	case 8: val = *(const unsigned long long *)p; break;		      \
+	default: val = 0; break;					      \
 	}								      \
 	val <<= __CORE_RELO(s, field, LSHIFT_U64);			      \
 	if (__CORE_RELO(s, field, SIGNED))				      \




[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