From nobody Sat Feb 7 17:20:11 2026 Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) (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 4D2122D12F5 for ; Sat, 20 Dec 2025 10:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766225709; cv=none; b=nI0ifYv9Jgyj/6esTzOIqJ52oKZZilzsGWqDvb3sBr7a6Lf6f+Yhx0ETiES9rOg1UpAuyw16BYUggWwFMSGbsfqEh5NOXcF8Ykm0bQI8TtGxH8D2JspteOLLTL+abfdKKDMrN5GEWlysBaf6u5/2OHLlKF+1aV/U8YTrjuTKuKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766225709; c=relaxed/simple; bh=XgPO0hAsWNCQiOjQGczv4sLfVnUly85+ZcGG2sJfq5M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=mBDbO7dyD8cWRvQE4XkqHpH7fjhQpyB2DJBk1gqmXwT0N4xiSK9KgXU+EEND1JjTN9I7CJAbltIzpWaGFaPKPJlN9J3Y8HGz+GrwZvLpkmZT6OzEcjaPZKzQ1dtfu79ttharzk0MroLFynGe/2W9OPp7UcTT8gXjEp9BPyZ7gAs= 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=XRefPVZ7; arc=none smtp.client-ip=209.85.218.68 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XRefPVZ7" Received: by mail-ej1-f68.google.com with SMTP id a640c23a62f3a-b7cf4a975d2so355532166b.2 for ; Sat, 20 Dec 2025 02:15:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766225706; x=1766830506; darn=vger.kernel.org; h=content-transfer-encoding:signed-off-by:mime-version:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=fVHxDEzXbk/Xf2kRxSmDqk5Pb7kP0hbOsktvoPVjFl0=; b=XRefPVZ7549Z4a9pCfAt38/Om8xRiOnkpQK5jVAHzxNFaLyZp45kegdVa7RBcUTk2/ kb6PnpnKX/QZDQulgsDfklnFyvM5Hhyhi7UMGr7mtqHHTMlc357TfCe5Qu1356b4sgK1 x4w9hAn6/npZ8jPhZiDwFLD4ToPfNLRcCVgyYBkrtNHhjcv8A5Xw/3IfHB6q8QbwCBLY xpKdyrI4NJOEN6BGnvA4HbeGih27aPHhC7f/lMH61b/nojvPiqxllgbR/JiWLJqb7QJy Xt5/qVRfDa7OHehvUUJEDDXr0nq01lJLazUzQGPsbjNqSwrgb/+rkaSwxovaNRoDMCbT ZQQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766225706; x=1766830506; h=content-transfer-encoding:signed-off-by:mime-version:message-id :date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fVHxDEzXbk/Xf2kRxSmDqk5Pb7kP0hbOsktvoPVjFl0=; b=aMM/gusu07RUoXguSQpnuu2L/tq4MVKlbIULznJM+/SbT/Xs7HDRI878Rfe8QZYihL RVG+q8n8A8faDUTv25T+MkU7m/GGoWLx7fQlvLov2HacEaCEnnpCPUAl4r8pRkd12QuE 3f01nk1mICDS1le92e+liJ5/YgXtdaM+4cDis2XAQhmduAbQT0DjZt5sKTteQmUll7yn JAYMSlPFRcKFMyMCUej8auirlH16m0wyB+tSpAxJfjPH2hwHtgnYWU43RENfZ2QvxcaA 5BBRayr0/90Nb/7tEORnCVDKvd7+ga20os0GWVN0Q7iOLj/KnmiMNgZXUwgpEfKmjEuG QesQ== X-Gm-Message-State: AOJu0YwijXMKMqeoyS2gYZrSilhu9IumHQZBZJBRtbBtTBndEVtTXYnH N+illWkF671JYrft2qlh6vjg/HVsK+KmTvNS639Enz+zpwr6kyWE+Viy X-Gm-Gg: AY/fxX49P+dxZZkaoOBEUtNw9xbnFubs54f+GwwYn/Z+ph86s6Z229ON4jDPNkZ9GUI enuWLzbkSxWer58JR4IVEwewFnAtS4YTTD3j4/R6DvgOSDrYrMrGjHOvGL3wa8gP9WAbKKmcYXd 8fGq1N0WadmruupRyVZiTynQMgFmAAdN7kGjm/STO3M/aReiDI3EndG8rB1t0a6h8eAcsRkolY8 04K7hjYLX/iSYYuyKMNg0J3E+u1EDvgW0VqcEFm2mpl2Wr4wbmLZqyPD+dLZivL+VykiYv2YcyJ fjHpTwhnzH3GowLcbA/a9u0urQF2AQeaIbSHEvEIn4R26KxEI4cDKegF9yXDJf6wdnWTiU1t977 jDSFTuETso4+1AgNf8AH0mXUcaOUaQOwDzemoZGW7f2ePd/mbk0CAYLyODSI8cPgsG4RiyTFQNB zsDXMu/X7dVL58pNj8eWR6bC+VjyK1/0s/B2Ynv7a+/ytCPB2AiP60fopD8/BuGIRFVonRzJ0Yo cEOfcXXS6N/2uAP X-Google-Smtp-Source: AGHT+IE5eTGJkJjpHeunWxKzrqAV6uc97/1/8sX1iJS8ACI3ylfEhFjHzFzmRsnWx2fjyuCekSXZNA== X-Received: by 2002:a17:906:4fd0:b0:b70:b700:df98 with SMTP id a640c23a62f3a-b8036ebbe4amr537935266b.5.1766225705290; Sat, 20 Dec 2025 02:15:05 -0800 (PST) Received: from codespaces-4ad828.m1k4x3cq3poebda54cltipn05g.ax.internal.cloudapp.net ([4.210.177.130]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037f0ebbasm457683066b.55.2025.12.20.02.15.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Dec 2025 02:15:04 -0800 (PST) From: Riccardo To: rust-for-linux@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Riccardo Adami Subject: [PATCH] rust: document safety requirements for fmt::Arguments dereference Date: Sat, 20 Dec 2025 10:14:01 +0000 Message-ID: <20251220101401.25361-1-riccioadami@gmail.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Riccardo Adami Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Riccardo Adami This patch documents the safety requirements for dereferencing `fmt::Arguments` in the kernel's `vsnprintf` formatting path. This clarifies why it is safe to perform the unsafe dereference in `rust_fmt_argument` and helps future maintainers understand the invariants, reducing the risk of incorrect modifications. --- rust/kernel/print.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs index 899bed9c08fd..5f54be97a6a0 100644 --- a/rust/kernel/print.rs +++ b/rust/kernel/print.rs @@ -25,10 +25,10 @@ // SAFETY: The C contract guarantees that `buf` is valid if it's less = than `end`. let mut w =3D unsafe { RawFormatter::from_ptrs(buf.cast(), end.cast())= }; //SAFETY: `ptr` is provided by the kernel formatting path for the `%pA` -// specifier during `vsnprintf` processing and always points to a valid -// `fmt::Arguments` value created by the caller. The value lives at least -// for the duration of this call and is only read here. It is not stored -// or accessed after returning, so dereferencing it is safe. + // specifier during `vsnprintf` processing and always points to a valid + // `fmt::Arguments` value created by the caller. The value lives at le= ast + // for the duration of this call and is only read here. It is not stor= ed + // or accessed after returning, so dereferencing it is safe. =20 let _ =3D w.write_fmt(unsafe { *ptr.cast::>() }); w.pos().cast() --=20 2.52.0