Received: by 2002:ab2:2441:0:b0:1f3:1f8c:d0c6 with SMTP id k1csp138596lqe; Thu, 4 Apr 2024 02:01:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW7+oXDR+oUotQyFH72391gv82i+MT+h1JcP9YgIHK3jDMFttN1enzScaXReeDXxg+sPLzVKD/Iha1Wl89pR47VNWKIdxrS5cVOI5hlxw== X-Google-Smtp-Source: AGHT+IFlaaHDRyjayb0A3XWsmdkswOH2R1ADyHVOFFShKWog/xh2FPAdP7r1y4qtt2nk43F851qJ X-Received: by 2002:a05:6a00:21c1:b0:6ea:86f2:24fb with SMTP id t1-20020a056a0021c100b006ea86f224fbmr1731439pfj.25.1712221309036; Thu, 04 Apr 2024 02:01:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712221309; cv=pass; d=google.com; s=arc-20160816; b=OetOZQzRSTBFbe1DZrcGzM3vC6VoiVDvzGcrVpV7p2sMT/gz73YxaQPtws2qPT7Jti ku9yE5VzZkE/wvnlgD1Od9jMAMgDK+f34aCYTV3QwcdI6uUkO1B/bpSFzptTnmtu+l41 8lk2Im+31kpz0ydHZrn4ttvETlWEh9nzTE25VS0qsrDbPNJf/1Yqn51zXsypncImQBXT 7GKAHBjAKF+JB6HHmsmhGkc8hoHwpVSq4fY/s9YZQkZSesQxNxtXBojbddPAjodJOnaM DX0fHvdRbfwn9XAYctI8hr3SnLD6LWQ7c0yImZZIUdDL2Gt/X/0XTydqlrjkiqckfaV2 MchQ== 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:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=IsWHRkAXzz0UFSHl8jcWKwFQLylEunjH34ao/KOO2o4=; fh=N6k5FdGVGHwlYHGMauTunFf8jhQTZm8yDRkhhQ4kksM=; b=qYIVhmsM/Lp4qCdY7alA20L16z5m2qJLerw790oBOFaz9wZH2l+fuM3RBjXXBHWjUu Yh1NN/+sG2k89C4uUaJc4pXPZoOqhZ39OMR5rrVrL7x+r4YIYaaewPj6CE9Leu6vwRKa H595G1cjOw43fIlE1fmRHcmokCrvqNFVaSi3NS25ECqs1HMMJ625zWzSq5+TCnLHoONJ VsCA7u6/r6NR8BD971Qm+sopiYqAOLFD3ZIu4Y4TjWhbFuNCkGHd20sPPQX/E1CoUTWU uBS+UaHApTjYXyEcOdp1/qHcmG2ccFbtpEif1QbkQw+LB1We1PdkqPMPCJg5EHmQpHTM BCMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=n3IppDF2; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-131145-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131145-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bn3-20020a056a02030300b005f0a539ba02si10870718pgb.729.2024.04.04.02.01.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 02:01:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131145-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=n3IppDF2; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-131145-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131145-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A8746282479 for ; Thu, 4 Apr 2024 09:01:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91F4174267; Thu, 4 Apr 2024 09:01:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="n3IppDF2" Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) (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 0E2281B7F4; Thu, 4 Apr 2024 09:01:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.22 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712221299; cv=none; b=kEyNyC1aTrHZnrjUt+j3gsqLEv4w59zv9uUFvA0LciTQg4/FDlh6HBr5MNgjeELDKeSfn5uPUETtDHKUb6jXYZ0B5uwhh4ebJ3PGV7OxmbBWhixp0fzZUcjJRkWPMAivVnoEk1txFFxJnembVc8L9CYF+vgjYxlJ/nmsI4Pg+vA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712221299; c=relaxed/simple; bh=Z/+X+5Tr3shbeJv5Dt06oyq1ofubRAN9gc2I5U/VGZU=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jxngPP2taxHYMKoJJSKKFVLMRzOtn5CK+/H2y6OasLNnzzcj53pUzR4gNIlv6/xvwajyOkynVwO7LlPzCJyfTF3M5wPB88on4rrgdFU0Ap4bIERBT/6SAXJ+THwZ6uI1anLc1bItIk/KKkPWur8KSZSbpKckMattc6O5K1EKEsQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=n3IppDF2; arc=none smtp.client-ip=185.70.43.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1712221296; x=1712480496; bh=IsWHRkAXzz0UFSHl8jcWKwFQLylEunjH34ao/KOO2o4=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=n3IppDF26eBYlHo3/SjMpauyZtRy38wc3c/ljWVqqL5zgkDHpFYElSp7LPeB3T0K7 Awby4gLHSFodM8e3Z6XP7WHuMtVuW6XZNM1KLaVkfESbvu1JKK8YN4WPhcEaaJbv63 Avf6LdO4GGGX/wZVBV+aKslc1YrRJkrOj/+ulqpYl8dAkMCqO2wbTUKx3xZqQzClFB 49e0DuVVcrDmxVVLTwixKU9Ete9f9l68ooAvLD7G5yq7Ddx/e9ucpybIBG56qSkaUi vToTqyhD/N+CLkJJRsOGwkT9tTcpMRn4KdW9dZfqnUDj69favdBsn9bPITmcOOZ1eX BT7QflqDLPBhA== Date: Thu, 04 Apr 2024 09:01:26 +0000 To: Laine Taffin Altman , Miguel Ojeda , Alex Gaynor , rust-for-linux@vger.kernel.org, Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo , lkml From: Benno Lossin Cc: stable@vger.kernel.org Subject: Re: [PATCH v4] rust: init: remove impl Zeroable for Infallible Message-ID: In-Reply-To: References: Feedback-ID: 71780778:user:proton 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: quoted-printable On 03.04.24 23:06, Laine Taffin Altman wrote: > In Rust, producing an invalid value of any type is immediate undefined > behavior (UB); this includes via zeroing memory. Therefore, since an > uninhabited type has no valid values, producing any values at all for it = is > UB. >=20 > The Rust standard library type `core::convert::Infallible` is uninhabited= , > by virtue of having been declared as an enum with no cases, which always > produces uninhabited types in Rust. >=20 > The current kernel code allows this UB to be triggered, for example by co= de > like `Box::::init(kernel::init::zeroed())`. >=20 > Thus, remove the implementation of `Zeroable` for `Infallible`, thereby > avoiding the unsoundness (potential for future UB). >=20 > Cc: stable@vger.kernel.org > Fixes: 38cde0bd7b67 ("rust: init: add `Zeroable` trait and `init::zeroed`= function") > Closes: https://github.com/Rust-for-Linux/pinned-init/pull/13 > Signed-off-by: Laine Taffin Altman > Reviewed-by: Alice Ryhl > Reviewed-by: Boqun Feng Reviewed-by: Benno Lossin > --- > V3 -> V4: Address review nits; run checkpatch properly. > V2 -> V3: Email formatting correction. > V1 -> V2: Added more documentation to the comment, with links; also added= more details to the commit message. >=20 > rust/kernel/init.rs | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) >=20 > diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs > index 424257284d16..3859c7ff81b7 100644 > --- a/rust/kernel/init.rs > +++ b/rust/kernel/init.rs > @@ -1292,8 +1292,15 @@ macro_rules! impl_zeroable { > i8, i16, i32, i64, i128, isize, > f32, f64, >=20 > - // SAFETY: These are ZSTs, there is nothing to zero. > - {} PhantomData, core::marker::PhantomPinned, Infallibl= e, (), > + // Note: do not add uninhabited types (such as `!` or `core::convert= ::Infallible`) to this list; > + // creating an instance of an uninhabited type is immediate undefine= d behavior. For more on > + // uninhabited/empty types, consult The Rustonomicon: > + // https://doc.rust-lang.org/stable/nomicon/exotic-sizes.html#empty-= types The Rust Reference > + // also has information on undefined behavior: > + // https://doc.rust-lang.org/stable/reference/behavior-considered-un= defined.html > + // > + // SAFETY: These are inhabited ZSTs; there is nothing to zero and a = valid value exists. > + {} PhantomData, core::marker::PhantomPinned, (), >=20 > // SAFETY: Type is allowed to take any value, including all zeros. > {} MaybeUninit, >=20 > base-commit: c85af715cac0a951eea97393378e84bb49384734 I don't see this commit in the kernel tree, what did you specify as `--base` when running `git format`? --=20 Cheers, Benno