From nobody Sat Feb 7 17:41:23 2026 Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) (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 352271B81CA for ; Sat, 20 Dec 2025 13:03:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766235783; cv=none; b=ODKNAjr/2fGO9elWjoYdm/gq8vSgcPXDBQnAjH4zy7G6xq1tEcHa0xWT6/TH0kE+p5J2hENVZS4ncFOVTfieT8iBD+ovvtvbOZl7T5pjmOur6sBXzwU0OV+5UZ7c8f+r/51nAWDMKIm0PYvhDED36i9qW8CwqB5cqVOygVGJT8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766235783; c=relaxed/simple; bh=05LHoiuSPBTSfyzJSUG75GOop8lpP0cxRU4f94/G6WU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=YU9x9DXyVW4Myl+TvCbUhqurRP9D9JFVuESTUMNo/JnRnZ7J06/9mU3LqBx5IpOQ9yAHDk4M8DMcnY3N+nBwCq/lWXpAjqB1kKcaXIa9KO4CWrzCrRK4lKDmUloPqCwBJSHPzDAs6kmAJLfer/iOE6bqnCuqUjkDF8ZKYiFWhxQ= 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=Q0Lg9y7R; arc=none smtp.client-ip=209.85.218.66 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="Q0Lg9y7R" Received: by mail-ej1-f66.google.com with SMTP id a640c23a62f3a-b734fcbf1e3so488839466b.3 for ; Sat, 20 Dec 2025 05:03:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766235779; x=1766840579; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=V7RIGHedqTvoAMB4Jqxtxps60zRuzPPKf7xiOF7nG2A=; b=Q0Lg9y7R3CvOf1p9k3Dv7+yHyfekhSycC+1Ka4W2CPmoPOB6l6EXCrXQnwGl4lR/di 8ffy7rfp8lNoTmwgYqJyb+gaRzPtvvAIrLyGrlU2S2rQxiGeKmZ9ONsdVCAPeMrD4+UJ fv9yLubbJqkl8We3VI2EatIDAGalwOkIndrxA3EQj9T6aJSLcZ+Ex78lAUZdYHiVH951 mMMl0NmeJoXfrgWZEz47pu8IPhihZuX7xdH69sUR+HCJIQXbT8qCeM1YH0mN2aTzgfLo y3Y7tDvjraZ3w2lwaZpmnh3cXru3QKCPK26IlBuz2b6epQyvxneQAecT6RRbSGICE1vy LYTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766235779; x=1766840579; h=content-transfer-encoding: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=V7RIGHedqTvoAMB4Jqxtxps60zRuzPPKf7xiOF7nG2A=; b=G2mRpUV/ZWIdOJyqaCKMQIMuwMCNb0UXDsKsVsE+NwVcEg+wHnYavq4Pz70zWWAF7N tkekwe++n8G5ukcwCeY3gbjkvXDK7zs0s6nujZrt6r+DF9fxXjsZ9sXa2ormHP5ADam8 aVAssoDwSgcUuldTMh7XNW0hu59GJOwrPYpr13SX/oFogeG96c0CKT6VPesyhvLrDM+j 7b4xfEIlYEf3nD38VcihVfCTqgzWNMy9n1EIOzgR86QP32mQ6U3NDpycwLFgj6BhDYEB /KLi2seMMlEKxqPhWbXmgCJ6aQJj4rhf2cXdSi9Fw9oyEA717ApgHkluHj+nzGaYyZNr VpeQ== X-Gm-Message-State: AOJu0YyrP5oXV4UGypi+XMTKBBn5vycCsQVkGKHW9s7I18l8hVdgZHjP Sw82A7t5XO0POjCMOVzNFs8c+fayTdb+lspNbI8JLj6KlUSFelp3irJueC8yw3lsdVY= X-Gm-Gg: AY/fxX5ytZuDDInTdFTCaV8w4jD8QpNBNm4KFACmFVQkJyhtCIfkzedK/lTFXycupMB a72Bw3za3pzGtYRp1nMPkiBPy1136EyPC0+Xszr+XKZOEdfeuKlICMdlgz3YvuhjWw6V3qtYJ3k QwLViW3eYS5CozwqRGi6Vk1npvATc6nAGbe5gYbBBCti8pp0Ptd+1ZEdzKLDmxa9ZYjbYMoOxTt AUM6wP46XMF3gAGZ4uVWhxTsBabjeoI36XRfIV/0ksGVKJ4rZSK3T0IctgRb+ofY9kKGOqjq+QO TII5HmZxNM+XZgS73pfJ42UfBqZqrRRT7PkSEU+rayqQwuJXzjyqkjrv3+Bk3a6sOnvtseihFIT Xz5NrZLTQIN3EJeOS2uHjsgGiWihIEfZl16PBHQbiW7R9seWkXHPOUww0SvGAryZdt0cuOqlWgN vXCh8W+A+2u7Yr7ghOs2RzVwEVGcgJEyn2bzurxzzoZLcJHMb7JKY7BbtKQYZBMJXTTdkkQge1E 8Hjp7xrP+R3uvmg X-Google-Smtp-Source: AGHT+IEt4sv0r1yld1dZFh8MPRnd0bauAeNkmQUxaYCYs60O9Jan6jQ2QuSsgx4NiyEpPi57zZmBHw== X-Received: by 2002:a17:907:984:b0:b6d:6f46:9047 with SMTP id a640c23a62f3a-b803722ba21mr632196466b.59.1766235779270; Sat, 20 Dec 2025 05:02:59 -0800 (PST) Received: from codespaces-4ad828.m1k4x3cq3poebda54cltipn05g.ax.internal.cloudapp.net ([4.210.177.137]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037f13847sm481981566b.57.2025.12.20.05.02.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Dec 2025 05:02:58 -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 13:00:13 +0000 Message-ID: <20251220130014.3961-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 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. Signed-off-by: Riccardo --- 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