Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1362469rdb; Fri, 16 Feb 2024 13:19:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUjol3Adl8Erddm5JdIC2O/q9TXtSk4vOCz2TkiTK96MbN9jsVG1q983nUoL9AeON9qh5fn+969ALnzD+o84pdqcoH/GnqDDHJcuVYPMw== X-Google-Smtp-Source: AGHT+IGkuwaZdP48dtPvt9gSt7IeC+eAj1M4N3KXFj/bRVDK/UXpdMEuDZ481qKwr63izYkgEE/E X-Received: by 2002:ac8:7d8e:0:b0:42d:dfe5:345e with SMTP id c14-20020ac87d8e000000b0042ddfe5345emr2851499qtd.68.1708118381987; Fri, 16 Feb 2024 13:19:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708118381; cv=pass; d=google.com; s=arc-20160816; b=zDNe0h9iDzSiCfi1LNlo6gxSEi6cWgnQZDhyXqQYBX1QmpaGFUfHCHC/8KAmnSDsqe lWbeIBcXPknRi6LNnq0MnlsTFMNTjqNSbjJbXY7N6g4poyyULMa/4gBIUMGz0zRcYxeI cpkBoLGlZhSbYcypPgJ7lRou+KzbLR5J+29i1Ap0dVvEOnjPYkZbh2m6M6P0C066wCBb iMS/uPoVfsDuGKPKr8oh7KSiW60aUeSKDqvWnGaiOQaRIsfl3F98UHTkFkcsDGMqnUaJ Xch0tVIg1Gmg5w11DJ6wJtGYfbLeaOUiezVzy8UjtHtSYwMoH3eLrPvJhn5ut9GZWPpn ltXQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Slargkifk+xN9eeRz4eeZrRCV6UdKDbpUow5tWWQ8Nw=; fh=fl9MfDgtY0e3ZfFVKyRg4aJ91N0LSKs8Kz0vayCvuG4=; b=I1N9aJ0tNw5mLlRc71LNMe/cLvZryNVGb9bRL0Iq0lo6V6dcitBAlJ2lLVVo3n6fID /xi0dPVl+JtOF8mT+xBsiPp7jSWHj2rmmBps4/Pe0SWMGxASXAhVaxJcztKBu856Ye3H b73WPmR5NKF911YyDreKaFMz5Ba+5IJDRJAVkrNtbXFbER+n5mrqI2ZHtonS1ll7HZJ6 dkYdrL7Z4yKK3X3q5FCDQHHxQznx09XXr9BPo4mAUfx7TChQWMI4GlhZXMjSZzzfbvHM LAMQP7PIELQD7FyYksUGyOI+uJ7wHXbev7o1CoYcQdqF5epFzr7mzG1b8rQMuHtYmv+J F1hg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="cK//LtsA"; 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-69361-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69361-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l5-20020ac84a85000000b0042c7c949b22si698139qtq.366.2024.02.16.13.19.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 13:19:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69361-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="cK//LtsA"; 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-69361-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69361-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B95F11C21DE9 for ; Fri, 16 Feb 2024 21:19:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 818F214600A; Fri, 16 Feb 2024 21:19:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="cK//LtsA" Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 319DF145B18 for ; Fri, 16 Feb 2024 21:19:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708118363; cv=none; b=e4QF98SI3H5IqKGD9Zi0ScGCPBhrqMgF4nDkPo3ov6lZl7Q61CHxp2Vjv3xUMNPjIzBpyMtxZB64V5afZ54QQSKvdx3umkTxpDviEpsk1vGxSabZWtw07LS4T4r0h5Cx/L6wdwy5Zhur4uWb6Ik2nNLdrFdLGn+NPLJSfMciZWk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708118363; c=relaxed/simple; bh=pjViwhXqVkFuRcb9TtMCBqAXy9IB1rtSAVc+/tWHUoM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kRsOXr3HTxulqNFnVihQhOjVFcoE94A18Idfh7r4EdqZ2wnYBW/Y11AsXMYfsB4qJklZuVuqn0Whd7FS3OdUX0YhUDJhsOeldURa34bdxDsUFSLohRmesNhybOx41sl5/13bjt8q3sTQMQ2Cl5EJhizrBdIXoXZ0XO4y+S48IzU= 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=cK//LtsA; arc=none smtp.client-ip=209.85.215.174 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-pg1-f174.google.com with SMTP id 41be03b00d2f7-5ce2aada130so2155717a12.1 for ; Fri, 16 Feb 2024 13:19:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1708118361; x=1708723161; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Slargkifk+xN9eeRz4eeZrRCV6UdKDbpUow5tWWQ8Nw=; b=cK//LtsAUxR2N9tqu1a4AEH4D2i/Y92EaTnzsi/SJFgrT3dL9zfI5+nNd3hAKDw8TP momltlpGm0AD7E5gBbFA2Hypdq/fvYQLheII8S3zF0ZQQyVWd6jtMPnlLOzwAUZntsRQ G5NCF21aCMVf1iM/jXLB2XOn8k+OuwQmGfaFs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708118361; x=1708723161; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Slargkifk+xN9eeRz4eeZrRCV6UdKDbpUow5tWWQ8Nw=; b=vqDLWdgqjAbOamEqNcLjFhpJa+8agGjvk0FVRpAuwbVOjNg8FPfvUNrxvsSIC2q/cj qPRUkmwW1aBnhonuwShWHu2rLs3xFs+jioaK8BpUhxhMMPWcjY8wlRyp2UuDsNlAg1m2 4EDN4da0VYpbG47Xx/7WZBgHfSrwLKKBu+LMBWjPrvFsKWwtAfTkKNgnPzBk6w/zXZuM e2vlzYmWXy+N7RPjWCO6/DLDzLn1Tb4efxtSHjgk0nUtq5HfzUEvCBmQL7V2tkWNACXy Vru2T7RYV6BAWbGJv6ccIHhaiKoWuMb0dn7UByKIZfMXthgKlvj9ijLrlVK5WGbkaI+s AXnA== X-Forwarded-Encrypted: i=1; AJvYcCVH7tvZeF0rM+0l010j6NrV6VN27l/aeyBRn7RVnz+hMkI7FOaKtS5JovUiqlWO0HxlBsFAfScSEg0fNCBbu9hg7MKEsWTxZpBqneUN X-Gm-Message-State: AOJu0Yx9LnbMpzWXEsNcZO2deojkAbRNG5vBwH9wj3xAjy15P8PTRy2l dxW5tGugZnb8QL8ukZBHYYGXgfPhvFTll2/ogzWeshq5D8MIREi1/cMPDuX9AQ== X-Received: by 2002:a05:6a21:670b:b0:19c:9b7b:66a with SMTP id wh11-20020a056a21670b00b0019c9b7b066amr6805585pzb.49.1708118361358; Fri, 16 Feb 2024 13:19:21 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id kq15-20020a056a004b0f00b006db05eb1301sm395754pfb.21.2024.02.16.13.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 13:19:20 -0800 (PST) Date: Fri, 16 Feb 2024 13:19:20 -0800 From: Kees Cook To: Arnd Bergmann Cc: Steffen Klassert , Herbert Xu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Nathan Chancellor , Arnd Bergmann , Nick Desaulniers , Bill Wendling , Justin Stitt , "Gustavo A. R. Silva" , Leon Romanovsky , Lin Ma , Simon Horman , Breno Leitao , Tobias Brunner , Raed Salem , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] [RFC] xfrm: work around a clang-19 fortifiy-string false-positive Message-ID: <202402161301.BBFA14EE@keescook> References: <20240216202657.2493685-1-arnd@kernel.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240216202657.2493685-1-arnd@kernel.org> On Fri, Feb 16, 2024 at 09:26:40PM +0100, Arnd Bergmann wrote: > From: Arnd Bergmann > > clang-19 recently got branched from clang-18 and is not yet released. > The current version introduces exactly one new warning that I came > across in randconfig testing, in the copy_to_user_tmpl() function: > > include/linux/fortify-string.h:420:4: error: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning] > 420 | __write_overflow_field(p_size_field, size); > > I have not yet produced a minimized test case for it, but I have a > local workaround, which avoids the memset() here by replacing it with > an initializer. > > The memset is required to avoid leaking stack data to user space > and was added in commit 1f86840f8977 ("xfrm_user: fix info leak in > copy_to_user_tmpl()"). Simply changing the initializer to set all fields > still risks leaking data in the padding between them, which the compiler > is free to do here. To work around that problem, explicit padding fields > have to get added as well. Per C11, padding bits are zero initialized if there is an initializer, so "= { }" here should be sufficient -- no need to add the struct members. > Since this is a false positive, a better fix would likely be to > fix the compiler. As Nathan has found, this appears to be a loop unrolling bug in Clang. https://github.com/ClangBuiltLinux/linux/issues/1985 The shorter fix (in the issue) is to explicitly range-check before the loop: if (xp->xfrm_nr > XFRM_MAX_DEPTH) return -ENOBUFS; -- Kees Cook