From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (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 95BAC30EF7B for ; Thu, 16 Apr 2026 03:46:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776311211; cv=none; b=Hsz3CDl6e4OrAreZ/IrMC5RxAsI16XTfc/2bgjKlWFr1tuxnKOlITesyJgrgR1sVBrYNvLtBRv9JJsDK6oeHIyltr04coIygP4twd6aB+0UwazR67CNE3istWeZAyxBT7nid28jLHxgdQ1rY7CKHK2pkLw2li8+mDe/zxP2bXTs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776311211; c=relaxed/simple; bh=w1aL7WYU6lAVaJQo8x8bYIFkjKllYYPVcpYi5VXenHI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VytdKIX7cugQdFcSFp3c+NR5YYoUdR30UZ3VUAo90/rhmpw16BwI4zjhzszr/YFxdZkTYR8jz93zXQ5puzK0ayVmaqndEd34/JtlqBcDC8pR2V7FtJaOmsIYpAnEQ0dLa8mcmARbYS5av7okZSiH7keEejfYFnI4lLwlmwNx7Qc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=On3ctYww; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="On3ctYww" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776311206; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZocjYN9l8oVb8KieLprgFd0j6oVTKXIFe8M1eMGD6+E=; b=On3ctYwwtz8QD6QKDpRHGQRM4M3y0jAP2EXJzUTKHkd1S1oHPp9R75+MZCAPIOTmcOLZOp NFQrjZgWcIWViajYOHRUftraxbVIU7iE/0Yq/A+gLkYhVW4/zu6X3nY3b/dFW5Eizpo8Dp Qq5bpVNIjqvjklCxIEFAK5gffQMlhQE= From: Jiayuan Chen To: netdev@vger.kernel.org Cc: Jiayuan Chen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , David Ahern , Pravin B Shelar , Tom Herbert , linux-kernel@vger.kernel.org Subject: [PATCH net-next v1 2/2] net: add DEBUG_NET_WARN_ON_ONCE for negative transport offset Date: Thu, 16 Apr 2026 11:46:07 +0800 Message-ID: <20260416034610.8873-2-jiayuan.chen@linux.dev> In-Reply-To: <20260416034610.8873-1-jiayuan.chen@linux.dev> References: <20260416034610.8873-1-jiayuan.chen@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT skb_transport_offset() can silently return a negative value when the transport_header becomes stale after tunnel decapsulation. A negative offset is never valid — it means transport_header points before skb->data, which will cause unsigned wraparound in any caller that assigns the result to an unsigned variable. Add a DEBUG_NET_WARN_ON_ONCE(off < 0) check so that such cases are caught early in CONFIG_DEBUG_NET=y builds (e.g., syzkaller, kernel test bots) with a full stack trace pointing to the caller, rather than silently propagating a bogus offset until something crashes downstream. Signed-off-by: Jiayuan Chen --- include/linux/skbuff.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 2bcf78a4de7b..0b1aeacc25f7 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3234,7 +3234,10 @@ static inline unsigned char *skb_checksum_start(const struct sk_buff *skb) static inline int skb_transport_offset(const struct sk_buff *skb) { - return skb_transport_header(skb) - skb->data; + int off = skb_transport_header(skb) - skb->data; + + DEBUG_NET_WARN_ON_ONCE(off < 0); + return off; } static inline u32 skb_network_header_len(const struct sk_buff *skb) -- 2.43.0