From patchwork Tue Nov 5 17:44:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13863277 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 D214D1E6DC9 for ; Tue, 5 Nov 2024 17:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828655; cv=none; b=pvBxxvCN61O3vOM3iSW/DJQ3UtDLA//q12z/bHZ3p3XRYhnQ0aBCOTkjdndPvZ+Rv2uCdYKo/XcSmSlYpwVl831Lk7VlYX1xmw3Af71DrtfqqnUeqsCPiZ2/QF0MYZWwvVIX06t9ROohUUXRcK6XjbYmaWiIjItfeXF+yiVBwUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828655; c=relaxed/simple; bh=J1s/lzxM/9r3pQA8JyR32+fZi56yZQUdaHdH2de007A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kRBedzkTmQ8QasHntsg16PnXhyNaChQXJrXFSYqSUCT3giK07JYRYlQAiRSRxHLRJmA3hE8bDyOav+njh5ZdnWMa0hwWgzHQcMDb+v0VrWEEGvcsLeeCwFWUFGbjuVAjtCIZDLcRDqCLAxqwkphDYl0TRPI52+JhrgyWFzGZ5Z4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jW6jv2G9; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jW6jv2G9" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e3314237b86so5303915276.1 for ; Tue, 05 Nov 2024 09:44:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730828653; x=1731433453; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LyQ4iSBUaIE+8Hy9IdFnubTi/J27YNEsIbYJcTy/f1w=; b=jW6jv2G9fVQMEebVflalHb3ODW4r36uZq5pF6NF19xu8xnQCIORTGvQj1O7DiHlolx zk2EMhljheY8PsJ4+BdiEdGa6zjiKoMifhTsJ7cDcclt6Y+nZsH/twCah4d8Rommw5np SeSaChQ79hBnPmyPlKEXs0n682MOquthz1JKQBCMs9JTnZnEtV7sDykzQw8v43DHF1do /lRLWTsJ8FzpDDHxTPbhZHkaFRo4ZKKKqruohclouhHn1qJ9ICyc9bVI3cucfbbEFI96 KCaxsWN+ype4rsWYifiz10yjVuh4Qs5We0wkcsrQ0abyuoE3EqsA/JsmpLNGKWH3fZNp 3Ubw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730828653; x=1731433453; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LyQ4iSBUaIE+8Hy9IdFnubTi/J27YNEsIbYJcTy/f1w=; b=ulIdNb096lDPyXskR7y6xkouk54Mtwmd3yWGyzd9ONCd0a9HRn+YyCJlJdnLtchYcE MQTLQOhugjJM+7Fg/sVM3i8hMSKb5CCITU1fFh9gL5H6na5kQMFksYDjxHNKn6TXAiHh lbP+qnMt7wwKBXmUBJOb/6wGLTZGk7NCN2tFvL6q0quspZsGGPV4YvJeUUPTjl2/Nf4C 6BD8c5D7TNZ0ga0E9hulvefYIAgGXjWcsLFGZW51i0Dfzl3/q9w7p8Lp2hPcoUZQjwyW KfsY2sHQf3PjVcst2FJfwCrp+zXOvt2GtvPDnzkrBM9QlQ2vZEseNQfH+J/bx/0pfh3q GXqQ== X-Gm-Message-State: AOJu0YzwhRv6zQqMbVyX8boz9jaeWIhoOUFqYISf91RZ6INvySAqX0s6 XQ257kO2cTPJmwp31TS1Cw1sPZeiVPynJY9qbYT19macLAdKTpNkMBcC44o0QjCB9j4eK3fSuYx X/uQiifMkuA== X-Google-Smtp-Source: AGHT+IGn45vHPnqzJ/Zhg+LkDUypc8OTWhrqworv3TQV90ntGK/FjInp7wEFBFSh8liy7F59bPi/B+TeVvY/GA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a5b:bc7:0:b0:e16:68fb:f261 with SMTP id 3f1490d57ef6-e33025817a8mr11550276.5.1730828652919; Tue, 05 Nov 2024 09:44:12 -0800 (PST) Date: Tue, 5 Nov 2024 17:44:01 +0000 In-Reply-To: <20241105174403.850330-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241105174403.850330-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105174403.850330-6-edumazet@google.com> Subject: [PATCH net-next 5/7] net: add debug check in skb_reset_transport_header() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Make sure (skb->data - skb->head) can fit in skb->transport_header This needs CONFIG_DEBUG_NET=y. Signed-off-by: Eric Dumazet Reviewed-by: Joe Damato --- 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 32a7d8a65b9f8f6087007177e763dc9498215e34..f76524844e7edc5fe4e0afc27ce71eed7fbd40f9 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3007,7 +3007,10 @@ static inline unsigned char *skb_transport_header(const struct sk_buff *skb) static inline void skb_reset_transport_header(struct sk_buff *skb) { - skb->transport_header = skb->data - skb->head; + long offset = skb->data - skb->head; + + DEBUG_NET_WARN_ON_ONCE(offset != (typeof(skb->transport_header))offset); + skb->transport_header = offset; } static inline void skb_set_transport_header(struct sk_buff *skb,