Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp654693lqd; Wed, 24 Apr 2024 12:45:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWy5fU2I3LCc2bsy6MnjI5xRieoJ1BWFAYnO92aPo//c/IDd0gY1PVV2aEvzKSQm/g6owLd6wLqtKfcFZBVovBmE9nfLCW5ShZNiNG9cA== X-Google-Smtp-Source: AGHT+IFEFQnRWxf/f0+2bE8tlPnd2ilNRPVA+i7gy6FmXDM8eX1wH7AX3H8+E4R8c72+pnVbEJ24 X-Received: by 2002:a17:90a:cb0a:b0:2a8:30a6:be3c with SMTP id z10-20020a17090acb0a00b002a830a6be3cmr3218589pjt.43.1713987902557; Wed, 24 Apr 2024 12:45:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713987902; cv=pass; d=google.com; s=arc-20160816; b=RbBTvK1EPyqBTrzNiqq4t80OVTWF1DrGOCMF6LYw0FnN8l5y2Y2IxN9xYXSfXo9+QK PYukzEx4XsqPjZcg+oAzwVxoJZAsFR7uVrBC3iGq3+/dNOuJMr394rayw7n/Iqr71hfe G0QQJHO4Xs5L3Lq6BpZ5ZMhRjArcBeXdRD+NUaygaXsuM/pC710Xk9UR9rh24buWCDyY mR46IGoMOnNIX64ok2oLxyUistds2r7TjNMJjLH3sFvGkR7P7MhmFJYZ3mV/MyC2Fp8b JSpJDx/IauzNIpZoqmdEaDdiqL8se0js8T+Opa+Dm8HI45shslqyR4xZ2jcdCQG5/PRW xzdg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=E5yDcYDvu79ikloFjmN2ArtCsis9cNcuVqbWpK2seK4=; fh=9kuowSgJbCUZur3Zmnc/CcyuRYilW1VODF+vupBvOXY=; b=knR0vga/WRN9VTWy5kLdHYWA1sqUoM9AIZCELK8r1sRQrL07UXg0WMzByFSUbpAUC0 JX3aDW4SFX2SRgPcOaII9iBdp9DeWK6YfHSlahb+060eWp+XIFMwW9585vmSY6z2hzrR zecnLcBtEn84fsZCF3oWBgZPPrglCMkAJ94Gd96YnUD/vAjbLgO23aKCfKTtcvBZEPzu 96+bdW66Edgua0dgznp6rQtHS4THd0GPTcmfqZMuYdcBtClne3KzTHI7XZj1lXY+bZKO clecjJ1cRqT60jdo80bSnDiNc8RAkuZch6kyxtS4tJ7NisEMBlijdOXHKbtaqpKlhUKj ikIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WdzHKOnR; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-157596-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157596-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id a19-20020a17090ae21300b002a29831faf9si11720342pjz.72.2024.04.24.12.45.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 12:45:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157596-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WdzHKOnR; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-157596-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157596-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7FD3FB24B56 for ; Wed, 24 Apr 2024 19:18:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE6C9568A; Wed, 24 Apr 2024 19:17:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="WdzHKOnR" Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 2E0635C8FC for ; Wed, 24 Apr 2024 19:17:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713986263; cv=none; b=YqAFowvJpglFXdnvuI5MyUQDw19GSrmnDkq1juAVFa31nF1bz3OLcmukS/rFDYUThWOes0kuXks/nvs5Krxk2YJRg72EgArz6bya0jJOlBZ4wuL6rVJa2poHzw3aSxLOX54XqwQRmb34dpPHDgyTmjQCImkfS8Taw5mru2wIoII= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713986263; c=relaxed/simple; bh=WfTBGnBFkRU20qhctvMnIHaixmJ1m8yq7qOHp+mKQX8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M4mtIEoAipSey0lvR/Kk7+hDLQ2aYGquD0SoRG5pdbHFPj1yzN+ahzX9YG0Cb77OT5wxDG+wO4Q4tYsHFJHsgADsZZFMbWMyO8BidcPTTUlokY+hlH8JGC3D+qJ1lLNA2FBbolpX/oFiIolL8z9bSVa7FDqvhx3EJ/aVOKhiEpc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=WdzHKOnR; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1e834159f40so1503685ad.2 for ; Wed, 24 Apr 2024 12:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713986261; x=1714591061; 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=E5yDcYDvu79ikloFjmN2ArtCsis9cNcuVqbWpK2seK4=; b=WdzHKOnR2NZYbZjMSuOUnxhgbN6UtJedTL0ijhz4M2j4e52gVe+Pt6iZfR0Rfl0JJs Lc4RQfwHcLmpOSzbRRQQXlj3pwkgaks6ElhyvlSGtFuKE9sBFzhzHNrBQxcF0wj3WujX SzmfZB1348TAfGvXZOEY8x6Aqk5/gTvCZHufU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713986261; x=1714591061; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E5yDcYDvu79ikloFjmN2ArtCsis9cNcuVqbWpK2seK4=; b=LWL9oLb+FZ4SvMJpB+UbgCrKT4RxSgUkRtUe994vJZNDPO5RsMqSZEOx6mTpMv6sJs 31LfqXv5istAiIRHtuvPzjPxWa2pAYadoZAkKqm0+lxJPRLcFOfV3kmzsyFyAIMceHOC Xu4miy/olP3YOJPWf3b7kx0yY7m3DCTN7lkQj7icONUgWNYmUCei1K9FqE/umu/zNdj5 T7UxcZA9wE8MmwBHm+VSibIN6Uju5pRI3p/NZ7ZAmMfPooXztt+RkvNDKU4TXtLRlYrd RhIzsFCKlz9rX6+0Kuz3esndTLQMFkS04VDPBzCvI1/0TOu0Os4dt62THc7IOwIj2ufL rYiw== X-Forwarded-Encrypted: i=1; AJvYcCUrch2B9LblDPg9KguxZ4rptYDDKxIEvD6ky5xf5+Xja2Z3mBh8i9qxkOwM9zbbk2EQoVAapqc0dCi83lMTLatU7rXWBShohJqvSjbW X-Gm-Message-State: AOJu0YxelfnA3VzTKwrDH0UI8LOVQ+O/D8h9SS8RwbXdu77xas6WJGxi BxbhfSV1M9Kp0ZRuv7JGjnAjtbxmriKr+2cnpvrj2hFOtrp4dA20WUa1TGQjrQ== X-Received: by 2002:a17:903:22c8:b0:1ea:9596:9218 with SMTP id y8-20020a17090322c800b001ea95969218mr1597370plg.45.1713986261347; Wed, 24 Apr 2024 12:17:41 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id f12-20020a170902ce8c00b001e1071cf0bbsm12295846plg.302.2024.04.24.12.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 12:17:40 -0700 (PDT) From: Kees Cook To: Mark Rutland Cc: Kees Cook , Jakub Kicinski , "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, Will Deacon , Peter Zijlstra , Boqun Feng , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Catalin Marinas , Arnd Bergmann , Andrew Morton , "Paul E. McKenney" , Uros Bizjak , linux-kernel@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 4/4] ipv4: Silence intentional wrapping addition Date: Wed, 24 Apr 2024 12:17:37 -0700 Message-Id: <20240424191740.3088894-4-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424191225.work.780-kees@kernel.org> References: <20240424191225.work.780-kees@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3326; i=keescook@chromium.org; h=from:subject; bh=WfTBGnBFkRU20qhctvMnIHaixmJ1m8yq7qOHp+mKQX8=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBmKVrRYEsvdcnHI4MuZvwNOd4oD1dteUrKWikwo S1OiHOayDWJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZila0QAKCRCJcvTf3G3A JkkcD/401uVxwndvI6fIAQZvmMpVPjLvFTgxS4IRuBU7Pqf0z0a5RSlHhEAeKEg4DA1/5Qn/Nk4 7VXgUWo66jWzFRmlmmipMniWFPzLt29JLEXmEIi/HV0UsKdhNmPyzFXJRXOKetIyH8MmkvA0nAQ PDrehyaM/tAewU/mTA9oiLtlT3Pg1bfNwDz5pvHwwJ+ON0Y6wxXaEqePkQt3WfBRCtTqIGaGl1e ow4LBS1klep8nsTmXBxq+ACfXBFNBrZebSFAuwGdlBJGy7EAo9NmKw4zZjqGze1GxLRsImdA8EI UxYMHW372KXbTpFeK0tNXvnb4mrDNqQ6a8FhdTEWDKMo5d4V2DHssDDI9Ol4XN/WioLS4gJ+wtm 1Os3DVpUl2LAzSNYLSEE1TokL+uJEMfnHPZLep2xANF25i11AnPPluIaEpGaMJrTKe0r2JjJw3Q jl0+qHCiCYcwTnajqt5uItmDrlePlJSVkhWTGJJK0TAh/aA28ei9NkULfuqGBG/QjMoB+a9EZyQ HXOifu761IGfEi9g62Q3Smz8Ha3KKrhBtCzTaGRrkW0/IFeGrE/iqa9cpRZm/hPl5dbuFKmFuPY zWTLOe3+l8OTPy5xS07j+aMrOmS+PihzCAw+ZJn7ax6TlLG1LcomfeZoMEIjNpHm1d4OPWK1BEw jpwKjUXXLLcV1Kw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit The overflow sanitizer quickly noticed what appears to have been an old sore spot involving intended wrap around: [ 22.192362] ------------[ cut here ]------------ [ 22.193329] UBSAN: signed-integer-overflow in ../arch/x86/include/asm/atomic.h:85:11 [ 22.194844] 1469769800 + 1671667352 cannot be represented in type 'int' [ 22.195975] CPU: 2 PID: 2260 Comm: nmbd Not tainted 6.7.0 #1 [ 22.196927] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015 [ 22.198231] Call Trace: [ 22.198641] [ 22.198641] dump_stack_lvl+0x64/0x80 [ 22.199533] handle_overflow+0x152/0x1a0 [ 22.200382] __ip_select_ident+0xe3/0x100 Explicitly mark ip_select_ident() as performing wrapping signed arithmetic. Update the passed type as a u32 since that is how it is used (it is either u16 or a literal "1" in callers, but used with a wrapping int, so it's actually a u32). Update the comment to mention annotation instead of -fno-strict-overflow, which is no longer the issue. Signed-off-by: Kees Cook --- Cc: Jakub Kicinski Cc: "David S. Miller" Cc: David Ahern Cc: Eric Dumazet Cc: Paolo Abeni Cc: netdev@vger.kernel.org --- include/net/ip.h | 4 ++-- net/ipv4/route.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index 25cb688bdc62..09d502a0ae30 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -537,10 +537,10 @@ void ip_dst_metrics_put(struct dst_entry *dst) kfree(p); } -void __ip_select_ident(struct net *net, struct iphdr *iph, int segs); +void __ip_select_ident(struct net *net, struct iphdr *iph, u32 segs); static inline void ip_select_ident_segs(struct net *net, struct sk_buff *skb, - struct sock *sk, int segs) + struct sock *sk, u32 segs) { struct iphdr *iph = ip_hdr(skb); diff --git a/net/ipv4/route.c b/net/ipv4/route.c index c8f76f56dc16..400e7a16fdba 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -458,7 +458,7 @@ static u32 *ip_tstamps __read_mostly; * if one generator is seldom used. This makes hard for an attacker * to infer how many packets were sent between two points in time. */ -static u32 ip_idents_reserve(u32 hash, int segs) +static __signed_wrap u32 ip_idents_reserve(u32 hash, u32 segs) { u32 bucket, old, now = (u32)jiffies; atomic_t *p_id; @@ -473,14 +473,14 @@ static u32 ip_idents_reserve(u32 hash, int segs) if (old != now && cmpxchg(p_tstamp, old, now) == old) delta = get_random_u32_below(now - old); - /* If UBSAN reports an error there, please make sure your compiler - * supports -fno-strict-overflow before reporting it that was a bug - * in UBSAN, and it has been fixed in GCC-8. + /* If UBSAN reports an error here, please make sure your arch's + * atomic_add_return() implementation has been annotated with + * __signed_wrap or uses wrapping_add() internally. */ return atomic_add_return(segs + delta, p_id) - segs; } -void __ip_select_ident(struct net *net, struct iphdr *iph, int segs) +void __ip_select_ident(struct net *net, struct iphdr *iph, u32 segs) { u32 hash, id; -- 2.34.1