Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1796000lqz; Mon, 1 Apr 2024 18:54:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVEyplehj5d1S5yI87n6QxY9sVDj0qK1DnNlFYDGPpTRYB2S+rVDNo/Hr6o1BRVMWoP53GmdJGADFnoAxM35nGQxsxoYmf+LHmp+/is3w== X-Google-Smtp-Source: AGHT+IH2zaWP+5vHuX6H4gwgkO+wBEW9JUGOHPkM0HSmxDkE0ine8A5M8vDRoqHb9Te49hfG7jT6 X-Received: by 2002:a05:622a:202:b0:431:5f25:9126 with SMTP id b2-20020a05622a020200b004315f259126mr12204906qtx.30.1712022853095; Mon, 01 Apr 2024 18:54:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712022853; cv=pass; d=google.com; s=arc-20160816; b=z+lGKi+C5E2hMEfUQM5g0vFEWOhYXmHPeqeKJx75ZxS7TvFinWW2NUUtnkm1re7UAF thGotERtQqdn5206BfUVGgbKankHWS6YT7AHfMEUB6BhCBZDC6fGgotZAVx0XyFlc5cZ G5++7RmnYlDe10+KsLuUaYp63kUIm3ai6xIZ7qFishU0QknZM+cEpu4HloUb58oFs8rX o5QOkc9UcbQoIrxy1mYf97P7Lh1XNrQ9vWVj7mr9JZETtkW+kfZOJ7oPVgmQzISUNoG7 UOndE5v/2e7aSJAuBb/cdcDmL1AqtYh58caf8FHuu7q0dam3QEGl46fEuOeUAGrbinIq R1nA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:cc:date:message-id:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:content-transfer-encoding:from :dkim-signature; bh=a9BDp/1jjLjWeDQ44X53i+aMmbsiLzmj4SIBII6L6qg=; fh=QowBVDgodzLbCPcbPjwAt0IRGeQ8iruAN099AN0k754=; b=IwR6ad50KMTH9HbGaYGGhnOm2WffUiGAIWVv4X+ojg6yVRxjipTyrkWnEekDB11Ti8 9CmBvmz5G2yHsGS1HOUUSi4MfnZO3N+N3pde/HfDmNyJVtw3qPnFOJJb+IsPcYWjqYhc iQOzlzVVyK4tHa5CNu+uufnqU4It1VrbyTzlZmvKWdGapJB+4AmabOpYYizc8dN90+0l cBOmUR6xyIA1x69SCL2eyxSO1ZOQd/i8X7DaF4qo3BR8Acr80BR+3h7y0o22bD0Q+5lL e6/xpCYI8vieQpLCzY69lbmE5JpdOpFaVvp7Pdiu6ZYtYY+6HnF6NqlCm5TNqoRoMyQi hGuw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@me.com header.s=1a1hai header.b=DtY4M0Vu; arc=pass (i=1 spf=pass spfdomain=me.com dkim=pass dkdomain=me.com dmarc=pass fromdomain=me.com); spf=pass (google.com: domain of linux-kernel+bounces-127270-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127270-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=me.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i1-20020ac85c01000000b0043136677cfdsi11128092qti.567.2024.04.01.18.54.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 18:54:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127270-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@me.com header.s=1a1hai header.b=DtY4M0Vu; arc=pass (i=1 spf=pass spfdomain=me.com dkim=pass dkdomain=me.com dmarc=pass fromdomain=me.com); spf=pass (google.com: domain of linux-kernel+bounces-127270-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127270-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=me.com 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 9E85B1C23578 for ; Tue, 2 Apr 2024 01:53:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE9FBDDAB; Tue, 2 Apr 2024 01:53:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=me.com header.i=@me.com header.b="DtY4M0Vu" Received: from mr85p00im-ztdg06021101.me.com (mr85p00im-ztdg06021101.me.com [17.58.23.180]) (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 92F30BA2D for ; Tue, 2 Apr 2024 01:53:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.23.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712022827; cv=none; b=Rsr4lAR7CqEN2JuOsb/p3HMzvb1vDJw0I1IYhoOFETek0KQBFX6xKdblwxlljTCEJgzLtMs4Z0Qt9JqiC4I5Q4SIk88NC0fnk0peeV9gPJJHJY7/eZWt8ned7WvUzssFsfhpjIQ5gh1o3AjZjM3+ybn32atFWqysT7/GDy8NfUQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712022827; c=relaxed/simple; bh=xo0xyMSV0jNOIMVjhXr3ayA4jB+lb62eMckivVCAKgU=; h=From:Content-Type:Mime-Version:Subject:Message-Id:Date:Cc:To; b=oa5X+ugir6NJRLX3YL+7ltca0gydPFYI2u48d34KiJOWlmY4Ip/eMA3gL1WxB2vNFam2qQ+nC5IuXhq7FZMdybDHGs0tsuIJyF96eNa8F1ssjSvW+HGf8bQxCZX+ekmQyn211cYSYtOFWE1onvYuLdOSKFgkHdVhnPYtjmVbBUw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=me.com; spf=pass smtp.mailfrom=me.com; dkim=pass (2048-bit key) header.d=me.com header.i=@me.com header.b=DtY4M0Vu; arc=none smtp.client-ip=17.58.23.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=me.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=me.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1712022825; bh=a9BDp/1jjLjWeDQ44X53i+aMmbsiLzmj4SIBII6L6qg=; h=From:Content-Type:Mime-Version:Subject:Message-Id:Date:To; b=DtY4M0VuaqJ1HkCHLKbouGac6BCyQWa/zlBPxDWcwDdae9XCXKlvcOKfQKL+ZkSFa uaFSu4mEDEsGF/b0vo3o+lx1rvxb7SB8XOKbviH561lsFTU33BiPKCHVpaLllJkcGK MsBHi61BRad+4kKh3CAPfBnFsk5DN2xeQa1L4xkUeSfr7t71saj9aXZK7fTQFnPhNI mXrVirKYD3e3pjMuu6IsYTB7K9k7KQGN7MW9UJab2hEzDHMLC5PlDnbuQx5bvMF7/M gYN8+/xT8pYoYsOakKsxa7kBnUXGoFIbz2LRhjIOST/L88EfjTExxx05Y+YaRpcuj/ qEC388jsoUwnQ== Received: from smtpclient.apple (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-ztdg06021101.me.com (Postfix) with ESMTPSA id 55F1F802E7; Tue, 2 Apr 2024 01:53:43 +0000 (UTC) From: Laine Taffin Altman Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.500.171.1.1\)) Subject: [PATCH v2] rust: init: remove impl Zeroable for Infallible Message-Id: <9D0C95D2-6239-4A3B-B9DD-66299B9911EF@me.com> Date: Mon, 1 Apr 2024 18:53:31 -0700 Cc: Laine Taffin Altman , stable@vger.kernel.org, rust-for-linux@vger.kernel.org, lkml To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo X-Mailer: Apple Mail (2.3774.500.171.1.1) X-Proofpoint-GUID: DYwoeEeKxN9Zee3bPJz-tAkjniafdXqO X-Proofpoint-ORIG-GUID: DYwoeEeKxN9Zee3bPJz-tAkjniafdXqO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-01_18,2024-04-01_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2404020012 A type is inhabited if at least one valid value of that type exists; a = type is uninhabited if no valid values of that type exist. The terms = "inhabited" and "uninhabited" in this sense originate in type theory, a = branch of mathematics. 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. 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. The current kernel code allows this UB to be triggered, for example by = code like: `pr_info!("{}=E2=80=9D, = Box::::init(kernel::init::zeroed())?);` Thus, remove the implementation of `Zeroable` for `Infallible`, thereby = avoiding the UB. 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 =E2=80=94 V1 -> V2: Added more documentation to the comment, with links; also = added more details to the commit message. rust/kernel/init.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs index 424257284d16..9353c9919fd4 100644 --- a/rust/kernel/init.rs +++ b/rust/kernel/init.rs @@ -1292,8 +1292,11 @@ 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, = Infallible, (), + // SAFETY: These are inhabited ZSTs; there is nothing to zero and a = valid value exists. + // Note: do not add uninhabited types (such as ! or Infallible) to = this list; creating an instance of an uninhabited type is immediate = undefined 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-undefined.h= tml + {} PhantomData, core::marker::PhantomPinned, (), =20 // SAFETY: Type is allowed to take any value, including all zeros. {} MaybeUninit, --=20 2.44.0=