Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp985672lqe; Sun, 7 Apr 2024 13:03:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVpNGQlnpOx7mp0loPT41S01JHupWcCPF6lKt7gNxg93gOMddAaCcyBlIlpPQ4BIbmnLNb58oihwWhqJE45nmtYRtqRr7uNa0jrC1stUA== X-Google-Smtp-Source: AGHT+IHhWk3Ny/5/hUZaYYR/WJnW88Q2Cecznjdfw7M/1BdoPtvGDVrygJFbi28rtH8gTgMIy91n X-Received: by 2002:a19:3858:0:b0:516:d04f:b58e with SMTP id d24-20020a193858000000b00516d04fb58emr5544943lfj.30.1712520238084; Sun, 07 Apr 2024 13:03:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712520238; cv=pass; d=google.com; s=arc-20160816; b=mWJ9WC63tzJUffyu+tkn6LQ7MdwyTn4SMCdGwtUULuDsSyLHV9YQAsKrF1rjhEp2BP sZQ8LQJWutsJVIaf0pmzkHb6qS66XmubV8vpCXZPKndNxWw+DzszXai69kq4OmPxitBM UI/kuZjygCfocYg2YLPKFWhYaPypbT5Si1MSvUfXG2ClIxjxlHlLrvP+ZiRbgzzkYAMk IBoXNGhsZV/FKvv+ctEAvZBvt/fELEfxCkPVdo4aaKAal+hocqfGabj35Q+B84XTQ4SW n8hy6YCBbQ3VqDH683XjolF9uVmYbllWPmf3DKicwNjNPxq7ZIhMuG6+51/Xc2jx9PCU OpGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=VB+pCgMJeT4HJ3tkJqRN6FhCakVW1xLtQCZILiBA4o0=; fh=XFtIYBWKUHeT7QeePRsvRu1E3Ye0pqVeBUuylyzJnt8=; b=aVbCczO1RinaUH1UYj92VGGAC03vX9/t89d3n3+4wqjMXibCfYgXfLPN8N7G36xcAb 02uiEf8C6P1ZS1O7+vBtttd1Upu/4C+oPD0IKq4Pjjme89JTqpNibwo3TPdNM6f1Dg+u WPdqq1x8qm775W8+fg54hdgEQXBzf4Ihnu9F1ZxxF/0yrkUMJ44eMdoWPtYkgktOcWML mu47Er6bDK/mjRlxtD8dyM8CdIuEXiACwpMFBA8kU2kppYUTXovrxVTzqYL3TAhDghpl pRsSqqU8qOHYSseuNvTPpq4Y3OzJpK2GRHnUqfV5hb89CW2o3SytsvHQL8z2ZsyuLpqL Mv8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VKnuCAY2; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-134632-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134632-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id x12-20020a170906298c00b00a46da57c560si3022366eje.996.2024.04.07.13.03.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 13:03:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134632-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VKnuCAY2; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-134632-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134632-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id A0F311F2139A for ; Sun, 7 Apr 2024 20:03:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BD173FE44; Sun, 7 Apr 2024 20:03:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VKnuCAY2" Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.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 D29F53FBA6; Sun, 7 Apr 2024 20:03:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712520201; cv=none; b=cuFDWZmLvXzfdQIvopMnc/boMoQcbRSVerfUF9xWmn7RRIduwd2OELtSZuSxZG1G0CMEuM126r2jFPlhNTqO8gSpgeMj4HvQwpmQ4cW+Ehcpau7T62rTnT1yN4zu/8k8zv6mPBj/XklzsA6GX7C3arzoDUKV3BkoudI46Tf9Gpc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712520201; c=relaxed/simple; bh=nkz3V1KnJRU4OVxZTLpNwOjleUUcWRpMJl+ozZfP2W8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ShuCEoXGh/Srln99OkztnSD4c8FTX4qIVvd7SSA7UoM/cc4WAZYwvwfA49GrcQoSsOmTgwTryT6TRPnwedTy34nBfIdRbr0g93zff3Ny4b6ROczwWbmTvyTK6rBICSqjqv0+sw3ufSWxzAaEN/Axf+slsxHtOA/1k2I+mRenVrQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VKnuCAY2; arc=none smtp.client-ip=209.85.215.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-5ce07cf1e5dso2691050a12.2; Sun, 07 Apr 2024 13:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712520199; x=1713124999; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VB+pCgMJeT4HJ3tkJqRN6FhCakVW1xLtQCZILiBA4o0=; b=VKnuCAY265HIr1RkUS0OPWh77AE3bZXqKsOOu10bg4khDnF22cvuHOEJcH0qxHNZYA GzufhCCPy0WpOXWMpFVoV8/x6RMjVeQrC8rhgTWaWFaz5GxPE0/KJPt/nAjhgzPrQlfo L1yfyH6j4EeqC5gTqNOobjZHGlC4o7+HS2Q7YrojoPIF2ht2X0UOKzxCNXbW4M6qLWIp HHIhmSEUTAvjDd9JN6ZGxXyCJp/L82BfXsBybijpiSPXtuMHE4sxAsLxoBysyPAXK8UW /gJSltCIpTLFlvxRgZP8SUq/79ZhhgOimV3HKoVfSRDoUeWUaZIvlJOXY5402zdCx307 KZzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712520199; x=1713124999; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VB+pCgMJeT4HJ3tkJqRN6FhCakVW1xLtQCZILiBA4o0=; b=CRsJLzFKD0eeFpGhDuYik6uAlwAM0BVoScdjcNbBheT7OlRF8Zu9XRrcZsvL97NB4t 3GRDWfgecNKvgzYU2GaJYv4z0NsRBZt+LqcJKX6jyvoAWsSxLzWvAtIqm6mJ3QZ+pTjY kzG80OXy5HaJSz2PhgJb/vZqdY+p+kc6bDGVpPz/gXgQOzUQ8N+s/Gl8RDZBuHzu8qZi OGIKPTKOpXKZipAn+JPhsgB8kEWLchZNMU7GPNBMRRpIqqck8ZgbVX9V7XuE/NS7Mj9T nwbu/LFO2gxZ00T4qepf8Iay0HlgYXntz8q5zAHCBfy7M7mimZZgTAp5nhbsDRNx8gXA selg== X-Forwarded-Encrypted: i=1; AJvYcCXtA64UgK9vxJ/54/aI5XYHvDv1r+pVuQvfu5cCqNJ8L65n4Amk1gVdEIJlZDpQ9TF4qUmpzAhGCw38AN11rBD3SFAqbSOtOQNr2dNFXrrvcmrRwtzGXqd35w9rh3CWqWMHHLEij08lNtyoUDf5HDQ9Nzt4GX/eyz4G2DEwRiNBZSrT5iE= X-Gm-Message-State: AOJu0Yyvo6eDVcavE++qpajp4Tv29q4L5BTWmvAXKyX28+J7cv4HdzpR kwmGlLQ5QakPqM9X3HbmQNMTzOUTKsT0hXDFuUb5OezBbEoSA2b5JNZK5LQWsiLC9oLKpqAh1qT yOy3j/tUuLpkl7jcmlAgEwiZeO+w= X-Received: by 2002:a17:90a:fb4c:b0:2a4:8706:ed44 with SMTP id iq12-20020a17090afb4c00b002a48706ed44mr4614220pjb.19.1712520199108; Sun, 07 Apr 2024 13:03:19 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240401185222.12015-1-benno.lossin@proton.me> In-Reply-To: <20240401185222.12015-1-benno.lossin@proton.me> From: Miguel Ojeda Date: Sun, 7 Apr 2024 22:02:35 +0200 Message-ID: Subject: Re: [PATCH v2] rust: macros: fix soundness issue in `module!` macro To: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo , Asahi Lina , Sumera Priyadarsini , Neal Gompa , Thomas Bertschinger , Andrea Righi , Matthew Bakhtiari , Adam Bratschi-Kaye , stable@vger.kernel.org, Masahiro Yamada , Wedson Almeida Filho , Finn Behrens , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Apr 1, 2024 at 8:53=E2=80=AFPM Benno Lossin wrote: > > The `module!` macro creates glue code that are called by C to initialize > the Rust modules using the `Module::init` function. Part of this glue > code are the local functions `__init` and `__exit` that are used to > initialize/destroy the Rust module. > These functions are safe and also visible to the Rust mod in which the > `module!` macro is invoked. This means that they can be called by other > safe Rust code. But since they contain `unsafe` blocks that rely on only > being called at the right time, this is a soundness issue. > > Wrap these generated functions inside of two private modules, this > guarantees that the public functions cannot be called from the outside. > Make the safe functions `unsafe` and add SAFETY comments. > > Cc: stable@vger.kernel.org > Closes: https://github.com/Rust-for-Linux/linux/issues/629 > Fixes: 1fbde52bde73 ("rust: add `macros` crate") > Signed-off-by: Benno Lossin [ Capitalized comments, avoided newline in non-list SAFETY comments and reworded to add Reported-by and newline. ] Applied to `rust-fixes` -- thanks everyone! Cheers, Miguel