From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D42191E32AA; Fri, 4 Oct 2024 18:18:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728065919; cv=none; b=AcUvSgIOEwBLAte73ao2vWhA8oxl77ddbiF7Pmqjj51x9/60deZuNfpqSvStm+meNinrXqKoyXlKIfOIEndyA2e7VNQ5uz2hD1ZsFHwFA2m9ZzA6RGtSrl2u4C2UXBsdp+u6mff2/GAbn3VfS7RCfiXkDH6i2eoTitdn2dTYB0s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728065919; c=relaxed/simple; bh=VrlpKBy5TNHBhTslCSmOmCDHVJEv+ytmNDHN7pQ4HOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=thehRWwI5km2zXHQzxnwGPc4d6s3mr2oJZSLmtaJOrkuFbusmuEVKMp+PseWkkIKWC7zZG3mAz6WQUr1dOgv0SIzU5VufbNmr2gqTtVY/ZPnCqzdcvd3MeTPGjb0wN3K+ifmXTtcyVngXsZ+P5UqUz13K5rnCMgJ5G03rVy4q10= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YMYOkPbX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YMYOkPbX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4446C4AF0B; Fri, 4 Oct 2024 18:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728065919; bh=VrlpKBy5TNHBhTslCSmOmCDHVJEv+ytmNDHN7pQ4HOw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YMYOkPbXdbhBWRW8dVhuANw/kTGPoyACtH+wW7++a8pzwWk+VS3Z4AXhqLmf/1EOL hYlBmMOj+sMl2aHC9m8k6DsJaSxXkVTBl7VlpMEP+1DFmj5oCk7iuAZ+84G5ajeUx3 GPIeKmiAVhkX3aL3AJHl0SehDi26T63esPwavaOM5TAc28Whx6DpfqtJMCy0j24K7h pxapYkVAMDxm0Yj5v4sK80vpBaQW0gwSR264q3hV7MENrs03S2eWBN7KAaZfXFruK/ GpgTKEJy2f2Skjqg4ci8BkMSrduUNbQ7WNJRBzuF/UG61KT+cHOyVuhcgi7X8m+Xxl Lp3pg0KQND1wA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kuan-Wei Chiu , Andrii Nakryiko , Quentin Monnet , Sasha Levin , ast@kernel.org, daniel@iogearbox.net, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 6.11 06/76] bpftool: Fix undefined behavior caused by shifting into the sign bit Date: Fri, 4 Oct 2024 14:16:23 -0400 Message-ID: <20241004181828.3669209-6-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241004181828.3669209-1-sashal@kernel.org> References: <20241004181828.3669209-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.11.2 Content-Transfer-Encoding: 8bit From: Kuan-Wei Chiu [ Upstream commit 4cdc0e4ce5e893bc92255f5f734d983012f2bc2e ] Replace shifts of '1' with '1U' in bitwise operations within __show_dev_tc_bpf() to prevent undefined behavior caused by shifting into the sign bit of a signed integer. By using '1U', the operations are explicitly performed on unsigned integers, avoiding potential integer overflow or sign-related issues. Signed-off-by: Kuan-Wei Chiu Signed-off-by: Andrii Nakryiko Acked-by: Quentin Monnet Link: https://lore.kernel.org/bpf/20240908140009.3149781-1-visitorckw@gmail.com Signed-off-by: Sasha Levin --- tools/bpf/bpftool/net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c index 0ad684e810f34..0f2106218e1f0 100644 --- a/tools/bpf/bpftool/net.c +++ b/tools/bpf/bpftool/net.c @@ -482,9 +482,9 @@ static void __show_dev_tc_bpf(const struct ip_devname_ifindex *dev, if (prog_flags[i] || json_output) { NET_START_ARRAY("prog_flags", "%s "); for (j = 0; prog_flags[i] && j < 32; j++) { - if (!(prog_flags[i] & (1 << j))) + if (!(prog_flags[i] & (1U << j))) continue; - NET_DUMP_UINT_ONLY(1 << j); + NET_DUMP_UINT_ONLY(1U << j); } NET_END_ARRAY(""); } @@ -493,9 +493,9 @@ static void __show_dev_tc_bpf(const struct ip_devname_ifindex *dev, if (link_flags[i] || json_output) { NET_START_ARRAY("link_flags", "%s "); for (j = 0; link_flags[i] && j < 32; j++) { - if (!(link_flags[i] & (1 << j))) + if (!(link_flags[i] & (1U << j))) continue; - NET_DUMP_UINT_ONLY(1 << j); + NET_DUMP_UINT_ONLY(1U << j); } NET_END_ARRAY(""); } -- 2.43.0