From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 147293A7593 for ; Wed, 10 Jun 2026 08:12:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781079176; cv=none; b=dnRFSpOXlGnhQrEcRYqUijsZkeOeji4A+d5H+rMFhX37fWsfnrIcjBxmCKyPMUVQnJcGEMzVX+RtqjTr5e4dpwXxo/ubw0ILEtkwNdyehv45Rghff+3CZ1FQ25lwEGf9xnKo/eKuqx+ZDGPEOTG+Dht8CLbUEB4G/u4/unJBiAY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781079176; c=relaxed/simple; bh=S+x69YITbLsuF4gVxjJS4UgkTpaYc+6Eg485Y1Iqkk0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YdjnFZHtP+92yUvH/LDngj7JFxHC6puvcNr+kvuNJ7+5RH8IxmsE/YrGanhQibYVdmkL2LdubXwmJQsEnZ9fS0KcXP9zF4xOx7NCS3sxKzvK+3YUbJRwEZs8i1lB6iIVeO9C82kpq5RSjlB0gY3JMiyTI3kT2rOaSJGz2uhDVUk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=sLnfHf+n; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sLnfHf+n" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-36ba3ea5c46so3852034a91.1 for ; Wed, 10 Jun 2026 01:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781079174; x=1781683974; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KIUSMLxfpzLCylhoWJxQMNLsTqrlPijUzWqPL+Fw5Mg=; b=sLnfHf+nJSm/B29AV4fPqP4QJmrgEFdH3RVz+RxI+c1XuCVxGXSWqBWCkMbuQqOkCK 6jgHDUUkyl02a1ZcXqDFfuQQS93y1DQ+7/e4j1+2jIE2gzT679Y3JCBM6FDwZQQEiQdt UXgTtj225cuL410JSEC4S+QpVZr1y/OypHWNIh8oLFQiDZtuEQr2mKr9x7z90XZmPCWd sicylnOb0t4fB+M7mOqCqCszSvDINSXuUOF2xWHW11EbZzECGisLFIUYXTZcMt9CYVJ+ mmlErGGc+o5wll4Sm8OBmAmppuwtVlgzzVyncpIVBZU/CtYzy/SzI/d9W20S/swYlfn4 VbIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781079174; x=1781683974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=KIUSMLxfpzLCylhoWJxQMNLsTqrlPijUzWqPL+Fw5Mg=; b=QY0aKaqILgsivAajxucvsF88i7pbWZdDnt0UjCnmJWYUdid9/Vist7bYgWpAdBVmEI kRFuR8R67octXi/7JbazMu41GKKb08INJzGUxSQDSrzYNl9r44x5JSfPsuw2UXKZRt+J 0hDYmXWMkh1Xa0Vx49cW+gDJq7w2ujFTzbZvICrzmBwJ99fis5ZUL1rMD5VbogQi1u0B a9kMuli8nX6ukhElLvKalGYhxWJ4wG6KwzDCenwNE9otENz/xZXCsmyo5SMi9MWSl6hc QlBp0Z9XQn/dcjncBpgc5InOsiMzZAf9yFtux1REcsWxA1mbrfDZM7cfSMECemv80elz vDvw== X-Forwarded-Encrypted: i=1; AFNElJ9b58gm4nNLbcZieTlXro+OCcE3Svt6irpWxMhXv8p8bN7Wql/51hp9KEhevMsPhHLkUPGFF67N577GOWY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxh/K9xrejizWskj2wVNKVO/tJW8kSaCK6BxGRDaAFBP0MjwfDJ ulUm/JKiowh/dfZvLZWfxiKCQKPhv9vbFXuWD0BVxcfQamy2gj0zFovPYxO2ykhp X-Gm-Gg: Acq92OG+9pae2Rq7i4KDZgDNQ8worLhgV7fqBmu6uoxc3BfHGeVq6F4Ar9CWrjGp8ky ZBhL4jtC/Kh8Q+kvn2chAdXRezcLM1moJueZCip3b32cEgpQM28QNHYthXRTAr/MoFllV2hHqPY 3LOgiTnP+D1cLDjEE2WiLFQZmQn/M7lfgOQ/4CdB0SCU1F3ALaaENnIczBzTUtoh2jFXzY3p/A2 Mv7JzMTCKEAM20qM/Wlhr6E/gctySp0b18ZnIrfd953Fs3DAZXNCQEU+Q0buXOzTVsScM3/JjwO j7ZEUX0zOSFwAteX5gb0nl+AbK5xi61mrFNuqmEDL19XzpmxZnwK2zCeLOlJAERQTH7m4xYivVi 6yeD2BIFL+rDgVn5lSxwOBpFSNp/7nrO6HYV6ZyhWsKAQVDkwKaaFEWxzOhOaaYm4Hf4sudmNcL tb1SaVm95nHkzh6NXUM9s49Dx12Vjz35LqVRHKcPTfo6wMkByBQRowNt1lG3fCOoLzmpdXvkFAw VvpV8s03UU= X-Received: by 2002:a17:90b:4c85:b0:36d:f28a:c5ee with SMTP id 98e67ed59e1d1-370f0f459eamr25027703a91.25.1781079174299; Wed, 10 Jun 2026 01:12:54 -0700 (PDT) Received: from cps-manycore-1.. ([147.46.174.222]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-37645c1aeb5sm1241003a91.2.2026.06.10.01.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 01:12:53 -0700 (PDT) From: Sechang Lim To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau Cc: Eduard Zingerman , Stanislav Fomichev , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Jiri Olsa , Shuah Khan , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Cong Wang , Emil Tsalapatis , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf v2 1/2] bpf, sockmap: fix integer overflow in bpf_msg_pop_data() bounds check Date: Wed, 10 Jun 2026 08:11:53 +0000 Message-ID: <20260610081218.506709-2-rhkrqnwk98@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260610081218.506709-1-rhkrqnwk98@gmail.com> References: <20260610081218.506709-1-rhkrqnwk98@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit start and len are u32, so u64 last = start + len; evaluates start + len in 32-bit and wraps before storing it in last. The bounds check if (start >= offset + l || last > msg->sg.size) return -EINVAL; can then be passed with an out-of-range start/len, after which the pop loop runs off the end of the scatterlist and sk_msg_shift_left() calls put_page() on the empty msg->sg.end slot: Oops: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] SMP KASAN PTI KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] RIP: 0010:sk_msg_shift_left net/core/filter.c:2957 [inline] RIP: 0010:____bpf_msg_pop_data net/core/filter.c:3103 [inline] RIP: 0010:bpf_msg_pop_data+0x753/0x1a10 net/core/filter.c:2984 Call Trace: bpf_prog_4cc92c278f4d5d56+0x1b1/0x1e8 bpf_prog_run_pin_on_cpu+0x107/0x320 include/linux/filter.h:746 sk_psock_msg_verdict+0x357/0x7f0 net/core/skmsg.c:934 tcp_bpf_send_verdict net/ipv4/tcp_bpf.c:420 [inline] tcp_bpf_sendmsg+0x766/0x1ae0 net/ipv4/tcp_bpf.c:583 __sock_sendmsg+0x153/0x1c0 net/socket.c:802 __sys_sendto+0x326/0x430 net/socket.c:2265 __x64_sys_sendto+0xe3/0x100 net/socket.c:2268 do_syscall_64+0x14c/0x480 entry_SYSCALL_64_after_hwframe+0x77/0x7f Widen the addition with a (u64) cast so the bound is evaluated in 64-bit and a len near U32_MAX no longer wraps below msg->sg.size. While here, change pop from int to u32. It counts bytes against the unsigned scatterlist lengths and can never be negative, so the signed type only invites sign-confusion in the pop loop. Fixes: 7246d8ed4dcc ("bpf: helper to pop data from messages") Signed-off-by: Sechang Lim --- net/core/filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 80439767e0ee..9cdfec2ca11e 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2974,8 +2974,8 @@ BPF_CALL_4(bpf_msg_pop_data, struct sk_msg *, msg, u32, start, u32, len, u64, flags) { u32 i = 0, l = 0, space, offset = 0; - u64 last = start + len; - int pop; + u64 last = (u64)start + len; + u32 pop; if (unlikely(flags)) return -EINVAL; -- 2.43.0