From patchwork Tue Nov 5 17:43:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13863273 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 15A231E285D for ; Tue, 5 Nov 2024 17:44:07 +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=1730828649; cv=none; b=Zc57nfMR4oFtWKolAKQsq0CrSv/PZsNahCghOFtFAXR3KMsU4kFQVTfCunnaOAMfvadQZz7Y/pSUxclh2YT2foMgg2il7TjQw7TDHiLqeukXzGy+ZKNjovL8lHx9AKFkOuMgiEi0PkzTkZYn4X9bxqNkH8hfCpVSYOUDlS1eDEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828649; c=relaxed/simple; bh=MYxeUBg12QQsE/3txUBzXdQMGaMsWXh0F6QpPFKQ/V8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rXXvEGXzLpUDgPdikaGvTCakw7pEeBm0Bm95vDgF5PgEgzQnVRHp1x4B2mAFsT8FxPt3k5OSpIYR5laiL1ay7tIZqtwmngxFlg2Km5jSA09Y0+86LJMNMKE4xVlxBeeSvFLKq8rNGcafb0cU0Sz0pAE7ZcY5eyxGafY/TSyTBcY= 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=quomWo7L; 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="quomWo7L" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e30b8fd4ca1so9498300276.3 for ; Tue, 05 Nov 2024 09:44:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730828647; x=1731433447; 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=xw8/m+j84Aso/IIgICBQUZuuE4Ec8riP8LtcSlAhsws=; b=quomWo7LOLRkVa79IeS3NCDv/aear5zRdzx0veIDXCEqpemc8CMpqjh3VMM+y5hMOi 5T5BNjZBopjB93WNj6AtZu7cOcBk+hsXd9zOJyFcgEE7UDu9lTqEFs1Cq5qwidcxBAz2 lLPOtMv+SvBggcYhvJMBIk4ON4WUmjJnzq5VEWlg+4DicoHPqH3F9RmB9T/asP+Dx/DJ FaBr+rwEzWIQMjzLdHkkCPY13dKVcJn700WTn3n2Xz5be1shYdBvcWhU/q4rGeIqAfA/ HbccwZLhxRo0H6FQ3RDRkgaIj8eHzCiPONhIJCjKJ5rGq9XVDUdHFGHFKIKv7E/V6xEx eCIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730828647; x=1731433447; 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=xw8/m+j84Aso/IIgICBQUZuuE4Ec8riP8LtcSlAhsws=; b=P6oPSXg4Ac8prRTM66RzZsGt0fioeYcH2wTv9R7viDqoVI9eS4NlCh0eelucigQDBj o0+p5vbDcjbYS0y/HDOs6zrBZ2Ac38+cPZMG+dJIq+W4rnLPC4V5N5bHR6QMNk3+J/UW MJftF8zytEqVkUZKQw0uG9nPckW1KaXBt/CqufcqE/o+xdWvnIe+Jn36aAe3WKP5V7J4 z+LwoA8/wRqd+qHIofaJ7BKXmJexqWZ+zDn5KbC5ufy428Fv3AftNGNg5LwdacOs/PRa HKg0nJChhJlb5VdZde/At09BdQagPej/RtU6ymvzUHoxGcQ9Q7kU7UwIPa4dFyQf7RMr jlMQ== X-Gm-Message-State: AOJu0YwaD+VtrZOIMU7qC1N5HnAt9Ob1Sr/ko4BC4hu2/3wjzAl29EEu aX9iKJPKjxIRs3+s4fqjpBl4s+kmttNjxV2+bqGJfTl6OTLUT+tniZTj00d5bZi8Jjyi052UYx0 SqqX2nAASLw== X-Google-Smtp-Source: AGHT+IF6+3GnYV4PmgUZ/Wk6hRPbw7wOB/pTGusSdwsgVVWER9yTlBqoGsIAriwFJ+thfacZ1P4q/oTYWX6Dtw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a05:6902:181e:b0:e28:fdfc:b788 with SMTP id 3f1490d57ef6-e30cf4d455bmr16596276.9.1730828647054; Tue, 05 Nov 2024 09:44:07 -0800 (PST) Date: Tue, 5 Nov 2024 17:43:57 +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-2-edumazet@google.com> Subject: [PATCH net-next 1/7] net: skb_reset_mac_len() must check if mac_header was set From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet , En-Wei Wu X-Patchwork-Delegate: kuba@kernel.org Recent discussions show that skb_reset_mac_len() should be more careful. We expect the MAC header being set. If not, clear skb->mac_len and fire a warning for CONFIG_DEBUG_NET=y builds. If after investigations we find that not having a MAC header was okay, we can remove the warning. Signed-off-by: Eric Dumazet Link: https://lore.kernel.org/netdev/CANn89iJZGH+yEfJxfPWa3Hm7jxb-aeY2Up4HufmLMnVuQXt38A@mail.gmail.com/T/ Cc: En-Wei Wu Reviewed-by: Joe Damato --- include/linux/skbuff.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 48f1e0fa2a13619e41dfba40f2593dd61f9b9a06..5d8fefa71cac78d83b9565d9038c319112da1e2d 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2909,9 +2909,19 @@ static inline void skb_reset_inner_headers(struct sk_buff *skb) skb->inner_transport_header = skb->transport_header; } +static inline int skb_mac_header_was_set(const struct sk_buff *skb) +{ + return skb->mac_header != (typeof(skb->mac_header))~0U; +} + static inline void skb_reset_mac_len(struct sk_buff *skb) { - skb->mac_len = skb->network_header - skb->mac_header; + if (!skb_mac_header_was_set(skb)) { + DEBUG_NET_WARN_ON_ONCE(1); + skb->mac_len = 0; + } else { + skb->mac_len = skb->network_header - skb->mac_header; + } } static inline unsigned char *skb_inner_transport_header(const struct sk_buff @@ -3014,11 +3024,6 @@ static inline void skb_set_network_header(struct sk_buff *skb, const int offset) skb->network_header += offset; } -static inline int skb_mac_header_was_set(const struct sk_buff *skb) -{ - return skb->mac_header != (typeof(skb->mac_header))~0U; -} - static inline unsigned char *skb_mac_header(const struct sk_buff *skb) { DEBUG_NET_WARN_ON_ONCE(!skb_mac_header_was_set(skb)); From patchwork Tue Nov 5 17:43:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13863274 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) (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 BAA0A1E3DC1 for ; Tue, 5 Nov 2024 17:44:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828651; cv=none; b=cTSizPSpqR4jU9zyftO6qLYTAxUBOW2W91WOShOwuaOQxSh+h+QDVyd30Sxlnn/uXk4KTL4gN5lr8b/lNSllIERmhLurzlHXgXgBuBC7QL9C10QpHAiEDkCnpEDEpAGPeK/weAbaotgItXHU92VxEow4PeFQIkLQjPp7THQQOyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828651; c=relaxed/simple; bh=LJOQMLlA26Q290qA39cG9YTSX7kqLdq64iNNElxTlac=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eZqDhRKAgsQ5QrkvXqpeNMGxtEjXilFdEtxmM3fBWGVPV82mtgoHkmZL9DY7mbgxk+t9Ez/bfZfYv0VVjFRR8Fg6B8bZTvTRQ/1h2vjdgox1mEnQJRzwndEEhVpXnGxgmrLrZ4lOO6nc+IrcMqjEypPmeYrZ4WgzqEu1ud3Wkro= 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=Hd5nxbTj; arc=none smtp.client-ip=209.85.219.74 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="Hd5nxbTj" Received: by mail-qv1-f74.google.com with SMTP id 6a1803df08f44-6d35062e1fcso79616436d6.1 for ; Tue, 05 Nov 2024 09:44:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730828649; x=1731433449; 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=6m10eq/NSUt3eEIqzqDeIdNeLEg07jANrEaMvtZtdlI=; b=Hd5nxbTj76mCsMnUlXcqXZBnvgsHF15JZp8Gb5gzSzr5uGXuJ52AxNdD8C5j83smPQ z920zaRzeAkt0La4Vnp7LL8Q+lDez0ZzADPTSEyoY4GTn2s4E/qNIvA7DBl1UALz14/p K4H3bdtD04RMet8256GPOsDoLwq+DYKyr4wVJfX+LXcjVv4JHkXCssPk3fxfayB0vTea TLZALRc3rilHMiopRvIPWMkM/qEFiuPNiiABDWTdmTiSUmPugEGFPTJ0K7vUQVln2QYw eGTK9mXgsDFp2ssJF4DFBMlFcHkVuxh33IKVySU1RrD1u4O0zIcH9cd0J9XSvA1SS7az 06rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730828649; x=1731433449; 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=6m10eq/NSUt3eEIqzqDeIdNeLEg07jANrEaMvtZtdlI=; b=d2cUaD+c9+l0494x8OoXDaZPbIcMWaEf0tZwgIJSErlc6jGaET4maHXLecEdeVmrG1 1eI79xrRPiusFEIkAyVD49Ltvus37Ge/yWxipQlu9ConuDufBQy9ZcBi9i31PQ/o7rB9 kxVSKEZPyLc7YfgZJFN3v/E6q0N2HGYJpcxtgoSIdGQG9K1ybKuqUavLyuISblhBpEWP DzBMteLKxLBC28fYw+LNKMsHrTwjz8G4rYP77E7yBaVOw/lHdbtzAVhg2aES47JuQcty rxyhf+mcPpNf+qnH2Qrq1bd6VkOlwlrIvqjU8ykNyWlvjyJEyxwY1PEvx/lhROY2413x FCFQ== X-Gm-Message-State: AOJu0YyzGN+XWcFvyB1CtjQPbTx1jF0pWgVhKS8mq43lcWb6Q7otl4wv 9+RUi3M9Ws7ZJ3Rn1EzH4EnggqaotKCxquVQjgQiWFJevSSmfH0LQfEBj4P6MjByKb6msOgK0c8 7Fb2EzyoNJw== X-Google-Smtp-Source: AGHT+IFi81xLBR3cNb9BziWG8Yd0ZV4rTpS1KI5i5jiyeedptgcmhhUiL6RKb5ryk9Knswf6HWxo6jbm/vFiWw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a0c:fc51:0:b0:6c3:5c19:e749 with SMTP id 6a1803df08f44-6d35c0802f6mr145556d6.1.1730828648604; Tue, 05 Nov 2024 09:44:08 -0800 (PST) Date: Tue, 5 Nov 2024 17:43:58 +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-3-edumazet@google.com> Subject: [PATCH net-next 2/7] net: add debug check in skb_reset_inner_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->inner_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 5d8fefa71cac78d83b9565d9038c319112da1e2d..75795568803c0bfc83652ea69e27521eeeaf5d40 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2937,7 +2937,10 @@ static inline int skb_inner_transport_offset(const struct sk_buff *skb) static inline void skb_reset_inner_transport_header(struct sk_buff *skb) { - skb->inner_transport_header = skb->data - skb->head; + long offset = skb->data - skb->head; + + DEBUG_NET_WARN_ON_ONCE(offset != (typeof(skb->inner_transport_header))offset); + skb->inner_transport_header = offset; } static inline void skb_set_inner_transport_header(struct sk_buff *skb, From patchwork Tue Nov 5 17:43:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13863275 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 360781E285D for ; Tue, 5 Nov 2024 17:44:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828652; cv=none; b=NzgZ3mRkXd6YoEGstN+Dw/RYvnXWeqYU+OhtNlEZt3Ed3aGuF6vkqEL6eWnGr1gyjukbZ3r9SzNcXPJBhQyokUs+bDn05veMVGSnb98omb2NHAJ5c3ZDQ4f0tZ7rRItW1G5bjglshqarF5S6iZBKMElomMAYMtZgLvXqfPtoPPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828652; c=relaxed/simple; bh=BeIr3Swz6ajsUdtnjxoFYHeaIUKCRo8so4bAz3l2jRY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bEMy4DCSId4xyyiBdpPwZpL48DyCl1cSvIlG5luU29hya58w/E2Eka2Kk/by7p9g3WK0jCkhKKlZIm5pRxN7NRpeDIp5mYzePXqjRpcV+L2NNxTvJfLFrYCnQ3oNCSeBQepCX+otU8uTIsJwRR2JZ6I94nkWnZB8SIED9h0o6pQ= 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=TPf6qtUy; arc=none smtp.client-ip=209.85.128.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="TPf6qtUy" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea8794f354so59192337b3.2 for ; Tue, 05 Nov 2024 09:44:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730828650; x=1731433450; 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=x8T44iTpXK8QSzLP5+uA52EIN8x9vg0thB5TAGN/oVc=; b=TPf6qtUyqk/EIzI8i1ndUR2zmRUq/Vadfc8cUSyfuGHIbnlQD8HhEcsYJ0MFf4+m16 lGTWXKTxYXc1pBqDzjUkTQqrvHbiDJwkO5zTy2DdfD/O5qrFXfAmavKW//DJL0mh9hcg baxHT1DBfqJ0yT0F12SWH7sd+qd6NMMcUKdHwjPTbzB60UhalBXwWq2i2MilQgY8zIgs ORmoP+ILAoUozqD2mlfSZivT8TLawebUvewgOxi/XTBbU0wbIMAF/tRM2X02Dt3kmfxr bnG7qeckU8Zb47rckOUIYlIymBZ1eOTFPnUo5d+D1S90l/XnY/dtexfqOsQDZe3A49eD YOUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730828650; x=1731433450; 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=x8T44iTpXK8QSzLP5+uA52EIN8x9vg0thB5TAGN/oVc=; b=BSjPe093xTgz2nQ1nMB65hy9TsBlQsYMuRh4BG3tLw2uNVQIgjcPW+K++ImVHcl4Yq el+Un9G+YxM7teZrTDBV2BBPIZs8tX6uM3TouIgvZ117eEtm8HpItGuY2RSX6laxKezf Z87lE63ZoapkmsyB7SZpBMGS9lPAQhNgqQK8j332jCcI+4NCWFiZ1Q9S7TBh6BKxqJyD ee0H4aF+4ifspecqZJbLzYZmG/9EUAZHmNlYGdSDXxoE+KLHuahPvXKUCFxdu60oEqTr pNVR7lGEl1hJV+MxCfFdV/IqsSXLeB/9m+ZEvHOPX2UcxMBA5/0rEVuxT1KWrVV55Uz+ jZPA== X-Gm-Message-State: AOJu0Ywet7hWaJ0b0ljDthonlwCDRLZHF7Eo7OliZ7GjY6sMovvPkWZm 6lJs0GSK65J9opwPezS3yWuqM7OH64OWCE57BR5AsJGQG8TzoYW5/u+3eLnmBdBEP61Qrz1LsDm Nqb+6gF+l3w== X-Google-Smtp-Source: AGHT+IGPB3ka1XsWxjty6yUf492L+j915SKA9lvENGEeB6KNQOJjD01wq9//1Usp7DruI2iLog0gvXAtZXpT4g== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a25:838d:0:b0:e30:cac7:5b70 with SMTP id 3f1490d57ef6-e3303408237mr16380276.11.1730828650077; Tue, 05 Nov 2024 09:44:10 -0800 (PST) Date: Tue, 5 Nov 2024 17:43:59 +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-4-edumazet@google.com> Subject: [PATCH net-next 3/7] net: add debug check in skb_reset_inner_network_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->inner_network_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 75795568803c0bfc83652ea69e27521eeeaf5d40..8dafd1295a6e921e9fba69b730286ea28fdc5249 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2957,7 +2957,10 @@ static inline unsigned char *skb_inner_network_header(const struct sk_buff *skb) static inline void skb_reset_inner_network_header(struct sk_buff *skb) { - skb->inner_network_header = skb->data - skb->head; + long offset = skb->data - skb->head; + + DEBUG_NET_WARN_ON_ONCE(offset != (typeof(skb->inner_network_header))offset); + skb->inner_network_header = offset; } static inline void skb_set_inner_network_header(struct sk_buff *skb, From patchwork Tue Nov 5 17:44:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13863276 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 9514F1E5731 for ; Tue, 5 Nov 2024 17:44:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828654; cv=none; b=ElFZ940V4FPLeC9RvLIbBI6qZT+ptPIuxXzhh4UEgi1+JwSmRu9EiMTfJbVhIiiOSiRIv1RlpngBxWuBcFnINYqiz8O3CvhC18074Py95HqrVmtDf8FnGl1E5u14TK3DcWkBjCq2ZfIdTWm7HNMgFs32VFyB42ZuS2Lm6PGNX7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828654; c=relaxed/simple; bh=MuGcy1XbX6kn3ZXD6dAvUfYIXmlqpINevK73ztYi2k4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DgByL7Vq4tkiFbJUiSCOwda06pWaCJPqzCznS07rJcm8Xqz8UvZNyibiwxFg+AqxldKE75pMWGyosTCsRLax5whzsdwO1HBvJYqFGpcEOhptaeYzIYBYyRcJoAmQ4FFjtbdwV/x38Sb+PGl8WI9EOxZMjrlnicMyXAyy7JDs0Ys= 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=ySm7TO72; arc=none smtp.client-ip=209.85.128.201 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="ySm7TO72" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea7c5805ccso59394087b3.0 for ; Tue, 05 Nov 2024 09:44:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730828651; x=1731433451; 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=Kk9RwcETdnYNnhnNnDFXbvT1xexMcOlxhvFlwxxQSeE=; b=ySm7TO72lfs+QWGCTtQv2Me670O9u6O0+pAbkDNSf5B6X0wdA4GbV0vX7NPV2LuQV9 1W8a6wBUvU7nvrutx7B28XtTClRHvdjvfaSPZX4IRZ40C0lOm9dF6S0AF2RdD3MJKo/Q cxDYskByr2pbT1btbzbJKLGkXjd4LQuKdBCR580fhDGQ6ELoLFwy9knZDNfV9Rsp2YTE Q716rxNwTMPVFkuHzG3h6eUZz6HNHyOjH0MIHnlu5neyjuPHK+vZ+9XP8UWfQo4WHbDv LOLYRM8OPZyUDH5G5b/TnB61N8TnAOjZ/mQIEuKelWiaUML320kGZVZzQUF75xGtAOOA HZQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730828651; x=1731433451; 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=Kk9RwcETdnYNnhnNnDFXbvT1xexMcOlxhvFlwxxQSeE=; b=BgiCIKBw4i1HbnkTRX2mCvkIvcqnv7n8jpL0fLbc8EzYCatYYKFNe8VwKt5uaLC5C9 0oBdHolysbbBwztPM04PROqS5kBqwU0F0t3a3UdD/gq1XMLdfuPOjmENLaLoN4Vkw1Nl zW3fg8Ac+/nGBbWXS2rDFzwjwRpe7kQvVcLxciKlS1k9jsyqYhk+eOToOYAg3vIk/pD5 aQvUvd/XOX9xiTNU0J6lR5ZYZOdRgmQCR58fWxn9AdC51ZdIZOOqJwYJCm5JX/gx/V2N 6gORO02TlcrxmEut9DFN94LAZ5Z7WuJ2oHNPGX7vHyMTl9D+ZrDgvpDbYwAONz5rutin lnig== X-Gm-Message-State: AOJu0YwqCnO3hS+hj/D9klxaziVGZ4bqHRnjX97IgNpB4tTM08ssdPL9 o/hFahD+l3H4XkbSPpvyVngGzF5BA85sd+7IQFEIxiIJFtYreCQg784cuVACloosAcU0qIpk9/Y fVzYo0nNdpA== X-Google-Smtp-Source: AGHT+IHMcRTane1j5KFKCrVyoZ2tWmrBOyzPZ3YAl6JYYQPvovZalnf1oLAc+LdjhTwAaesXrriUw9KnslPaTQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a25:8541:0:b0:e28:e97f:5394 with SMTP id 3f1490d57ef6-e30e5a3e278mr12995276.4.1730828651533; Tue, 05 Nov 2024 09:44:11 -0800 (PST) Date: Tue, 5 Nov 2024 17:44:00 +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-5-edumazet@google.com> Subject: [PATCH net-next 4/7] net: add debug check in skb_reset_inner_mac_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->inner_mac_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 8dafd1295a6e921e9fba69b730286ea28fdc5249..32a7d8a65b9f8f6087007177e763dc9498215e34 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2982,7 +2982,10 @@ static inline unsigned char *skb_inner_mac_header(const struct sk_buff *skb) static inline void skb_reset_inner_mac_header(struct sk_buff *skb) { - skb->inner_mac_header = skb->data - skb->head; + long offset = skb->data - skb->head; + + DEBUG_NET_WARN_ON_ONCE(offset != (typeof(skb->inner_mac_header))offset); + skb->inner_mac_header = offset; } static inline void skb_set_inner_mac_header(struct sk_buff *skb, 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, From patchwork Tue Nov 5 17:44:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13863278 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 5E8D81E7657 for ; Tue, 5 Nov 2024 17:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828656; cv=none; b=VxF/4g7n6ghBNK71myHGNU/IapUfmIB4pvlgP+usbZiD/sE+9fxWKd7XcSjhclgqzcJQ08e/ymq0YdpvmkyEeGrNt/iEZGZgembnTZhZ4AjO+No2pQ/qF2QB232+9k/jhntwfy8C7sUBU/bWs/nsEOr2bQ/1jmQVy22H48PqgnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828656; c=relaxed/simple; bh=kVUo6zaBQi9wbPpamGGxhKLe03edUpxv+cWu3BPgKGo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FO9gkUklJXD0y2M72DJaV3lPA9p8cARSuT/fFfa5VMshwKdyGCsHj1oPeAr5QQfakJfSS7qrEyk/p6/Xcqb9cdVjRQRh/Zisv4fk5VojZPbx4nWM7yCvqh9DFdLJpw0UoblyN+CQNI1JW71bFZTNpVzXepXjbX3Dc78tFV3IQ/c= 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=J15mcQln; arc=none smtp.client-ip=209.85.128.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="J15mcQln" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea6aa3b68bso70711877b3.3 for ; Tue, 05 Nov 2024 09:44:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730828654; x=1731433454; 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=pkFhoBGw2fMX7qk4RY7eJRvFEk6qririOfq2q/JTD0k=; b=J15mcQln1vuqgA+048jQZxAsNDm4n4Vd2hblSXdW4hQj/xHDGPLlCD+Gc1OkA4RKGb P9eD5H5zQ3uxidzWcNf6Qy0hbhKUkcmRQo/xykYfOhz3RqzBsctStb/EpT6crtuzw1pA zf6iKR4dmFWvF8xd/wC9WIa0qvKJNv67ggzYPfT9G2a1ym1xn9DUfuSjjvdWdm+MochJ YaLwcdGEXjR1Oc45fKTyUDYGxXwht9LO4En0xoAgSceM0nJSvAUGUK0puoolGoduFU+m BMCAeaDh3zuIIF+lfUtBdvJAk5eBZZoZcC9x8T6lsyILRsXQE6dtBA25k/X4wyKB3xEl Zdeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730828654; x=1731433454; 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=pkFhoBGw2fMX7qk4RY7eJRvFEk6qririOfq2q/JTD0k=; b=gi+gMXeeXLW0Pp8M+V4jPkYw95YKWFqP7YIfUnTVLV1t1qARx8cGZGnYb9VNuBZ/rL 87IQYLU1YpJVxLgQ8C50OY4Uhb36OSK55uDegBKl2hhCyTw46C5zfat/Tj8n7Wh06hY+ CInq1tZ6wy52bMhYMocO0e+zxtrm8tspNuvfhMW17kgpU8MgYyE+7o3Rc5VuAu18pp4R Bt2paiTDBTziBafp8GuCkzTYSvJU0BMRwmMtqtWf8qloKYtr5R+BuhAMOb8GzQvEfIdc lRy6Ah8dOlYOZQWwbw5QEhrjAXKvSAIe1PpX8PARzRm+xctj+ID3+BAUY6+3iBv+BY6y rBHA== X-Gm-Message-State: AOJu0YzoUcryusJSAyvmQh7HQN5fp0J4DmjGUB4SIZ7WSPDllU+ZbIBd fmj8y2C+xKnXIR+yyz3Xwm78tYX/gzSZ2D5B/OxT0dI7OjtVSCg6jqFJnHzc/TGN5TpRK1myAfr LWO7maBsP1A== X-Google-Smtp-Source: AGHT+IH5s+0BMJidg8HcVXuPqjML0RNhP9edcQI9ULnlbtEHO+PQyDLD5239sZGwAzR4qWd1GrWD67UhELyN+Q== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a05:690c:998d:b0:6ea:34c5:1634 with SMTP id 00721157ae682-6ea525566admr1103877b3.8.1730828654390; Tue, 05 Nov 2024 09:44:14 -0800 (PST) Date: Tue, 5 Nov 2024 17:44:02 +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-7-edumazet@google.com> Subject: [PATCH net-next 6/7] net: add debug check in skb_reset_network_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->network_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 f76524844e7edc5fe4e0afc27ce71eed7fbd40f9..f1e49a32880df8f3716c585d13c1085a2183978a 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3027,7 +3027,10 @@ static inline unsigned char *skb_network_header(const struct sk_buff *skb) static inline void skb_reset_network_header(struct sk_buff *skb) { - skb->network_header = skb->data - skb->head; + long offset = skb->data - skb->head; + + DEBUG_NET_WARN_ON_ONCE(offset != (typeof(skb->network_header))offset); + skb->network_header = offset; } static inline void skb_set_network_header(struct sk_buff *skb, const int offset) From patchwork Tue Nov 5 17:44:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13863279 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 103491E7674 for ; Tue, 5 Nov 2024 17:44:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828659; cv=none; b=O0SBO3I/3jDNS7z2MCQE9ia6/NIfQea0g90UX5BwVJ1W2w4VqYdEuL4pHWcengKxegerOydi5dmHnBl6uEAv8haDsPpgkbsnvwO0JzwqSLVGfZJRhLUopQ6JVPhJWDH5288dleLp32J4qoC6yvMjVI6VGOBp82UvxsiCumhYJJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730828659; c=relaxed/simple; bh=4CoG5ztSfhB+vYqibwMru86twfsf2jRlsBKwksiaUPY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ef3C39thLnrEqy6jt8IlvvC6kTla1e5VH/O2HNyAHhV4g4rWyPDdOjjQAiM5T0YoagYbTAsBXuOPbVQ2h3BLae/fPPbuDajgpN42yt0c9jwPgYuYYmndJlugsPjy9aTgpn8P38y21WMugq9jd6xH4P1PcSgMirxVThbA5NkoOUc= 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=zPBs4epo; arc=none smtp.client-ip=209.85.219.201 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="zPBs4epo" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e293150c2c6so11973459276.1 for ; Tue, 05 Nov 2024 09:44:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730828656; x=1731433456; 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=h2xIpKVQIkM7eoYB+vOYUgDYcFmV577zVnf0QyWtYmM=; b=zPBs4epoyMa2DT11Ih0CBMa56dXKj4y+6Dlf4/mUiR6qe4rDLgBCmT1mN1s9qIw8DI 3rzOUDzv5hXZqyHxwwM0Gk3jhu9sWz3tbtIcmzSzBSfcQjAKdopVxrce2MjpDQXqLbxZ BSXgWpi/jnJyC0M/asUS+AgqVfPeDabazFpd9LOeYvV0y9mBvWZm2Y6oGJjk2XMPlsqa 8/O/xlBaIMWgd3TSoiexXe9hLM2owlK1+puhXmNPE81yi0kMoFBQr1/1NzOkpmtFxW7g s+ApBx6+3YgLRArxV36R9N0vYfgYlp17JJ3d0V31wxOjM0H2TksazN7Wu9KeAMDe8Ww0 jWEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730828656; x=1731433456; 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=h2xIpKVQIkM7eoYB+vOYUgDYcFmV577zVnf0QyWtYmM=; b=K0Edntw74ZNLKqzC9rPyQ3XLot492uNbYmYZi/CKUCy3Wgys9RwcGAGYXOXTTzJMA2 8SGsavyHJKCjCnhLiEX4P8QZquqIMU/3ly+SHpEdlRa8PZi9PVBrFzRCNnzSHw/njM18 6VcI5GiEfzlNL4PygpYiGAoHVJlWYTmrkUDGsoNuQ6kqKP7W7SW5MaiA9VFYirNmASFQ MznTCA8BNWgmQeDn2FxJN5osD9hJv01hu3D6cANbISFbs+AZIQn93lYKZKwpnkE8sq3Q eMhx7xarnfW0KBa1yBvbD1y9wded4PCA6qnikVNBbsQVuXuKQp+jtHoGtNAmi/pazJ5A wfHA== X-Gm-Message-State: AOJu0Yxhy/h4jEUJv+SH8SvYW2CZPa+PkR9eQjEcW6KJlYjzTb9fSHxQ 4Zb5aiX0ZLpvZeQ4PiOqlGW2+OBWW9bAMRg5sSIpvnugF+6V2+qbXo6Tbwsg0hElCK07rDuP+wE OfIX+Do68bQ== X-Google-Smtp-Source: AGHT+IHuptGGLFCS0l+E1J+sCfNq6XUuYmz1xc3jw8jSb6X7SlAhgLgvWn2zHXJ14S/ygJDgKciTlVRyX8uDyw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a25:a2c3:0:b0:e2b:d099:1a7c with SMTP id 3f1490d57ef6-e30e5a3e458mr12118276.3.1730828655882; Tue, 05 Nov 2024 09:44:15 -0800 (PST) Date: Tue, 5 Nov 2024 17:44:03 +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-8-edumazet@google.com> Subject: [PATCH net-next 7/7] net: add debug check in skb_reset_mac_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->mac_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 f1e49a32880df8f3716c585d13c1085a2183978a..e5095d75abba18c5c5301ddc39c40cdcf5e528ed 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3063,7 +3063,10 @@ static inline void skb_unset_mac_header(struct sk_buff *skb) static inline void skb_reset_mac_header(struct sk_buff *skb) { - skb->mac_header = skb->data - skb->head; + long offset = skb->data - skb->head; + + DEBUG_NET_WARN_ON_ONCE(offset != (typeof(skb->mac_header))offset); + skb->mac_header = offset; } static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)