Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1728996rdb; Thu, 25 Jan 2024 04:37:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2IvSj00F9MCHweV/Hz72l/Sy3FMxj723zDejLr9YfL13nxsHuYnQlzoauaUs7Z0+eXpNJ X-Received: by 2002:ac8:5708:0:b0:42a:42fc:d445 with SMTP id 8-20020ac85708000000b0042a42fcd445mr878925qtw.26.1706186250361; Thu, 25 Jan 2024 04:37:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706186250; cv=pass; d=google.com; s=arc-20160816; b=C6wOIq4HI/4SI7AiIXbUb5omNogRMHZR6amfpIDe9omT9MGHhPj1osUsXOKi9sTVbH PLKs1UAj1LPE3TkD5WkYH14LwjO4gnGRX6KHJWGRIkeM6w43nxGkJoTYGik6zrKelcyC HKAK3idutxu8LIvtYouw/x/VznTCF9ISCbRMM8b2dG8hvaVtxW1Si0mQoaz8QXBZ7UOS p8ZXTM6ACO44q+gm2ystdfiTOtD8VFZs7aV3RILeS5crm2v9nTZ87SjtUCOmZ9OGQUFj edlAn3l8QilSgdgSX+8JyAcrUCB5ntFVA6oOb9RUvPtK9t75OAaaxylYzFDNC3Ui0Tkq Bx6Q== 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=w/8P03y0gIOgiGCcOtW8CKbm2M0HUIblwn8rbFoZDFY=; fh=gjdK0mn+rEqakIwN7X+XsBynu1JSiFVvhRjmNblSFLc=; b=VTolMG/6iNqwN7oBty9Icvtk5OQ7NU/IkaCpplzCjWcTlNzp1iP4MbJjUUdO1cLkX9 Jc0rbv+lSbiPF0SiFMdNnSaAUG8+U1HFuxzpQrHRY4sgXUt5B10jcuJXuVyRAfO/POaO Wrmi50xniDfS6K1YiRCXLIkd94qsHNWCs6kq0rOwPBkX8V6B0utXTdD5XRhjpggmqJkI lsfXW5+bS8BuJAFRtsVNtVdyau1SaEvm5OOzyW2LDu1ayOlDgGMMz7XB4nmUF2KKBpSf A+b5+8rZIRqDQh4JLAkCO9wYGhCcZOKOSnvJ92RF/f/eUs/gpQssY8ZUupJtFbdyrhiS kgPQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bDxO8Vvq; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-38587-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38587-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p14-20020a05622a048e00b0042a3521957fsi11385853qtx.175.2024.01.25.04.37.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 04:37:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38587-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=@google.com header.s=20230601 header.b=bDxO8Vvq; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-38587-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38587-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 225871C20E77 for ; Thu, 25 Jan 2024 12:37:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31BE2481A8; Thu, 25 Jan 2024 12:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bDxO8Vvq" Received: from mail-vs1-f52.google.com (mail-vs1-f52.google.com [209.85.217.52]) (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 D63F1321AF for ; Thu, 25 Jan 2024 12:37:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706186241; cv=none; b=s2yPoZGwMA1wBgYaRu3L0q2kDXR6oq6ATJ4j6LWKUFDmPA9O9GuYE8S3yv5COPJgKg8TAw12uf13TNzrHV0Lo7VK1anWQDGehleiqdp9cCryOwvYKHVJC0bGUxELpKIpXGnZonyZ07t/EVx9qkAPWJlN3WsE2+1UW6os/TxZ4I4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706186241; c=relaxed/simple; bh=FMcXpHB/zoqwhqTm+B0dEtaw8ZbOK6U7VxIx0G1qHDI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=q9Al6MV4InOZwHeW0eUGGUnmqTnv3Jg8a241O7x01f3OH4AE/eMUQmA89iH0wi8g7h0crqo849H4P5APAkHvhC/uh0hR6Td84CZjJaA62/4NXarVcBP+wjYwCEcLGL65lADuey5y7xFhBFgsco62k/hfARplhVMI9/ABdkglgPU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=bDxO8Vvq; arc=none smtp.client-ip=209.85.217.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-vs1-f52.google.com with SMTP id ada2fe7eead31-46afeb936afso901797137.1 for ; Thu, 25 Jan 2024 04:37:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706186239; x=1706791039; 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=w/8P03y0gIOgiGCcOtW8CKbm2M0HUIblwn8rbFoZDFY=; b=bDxO8VvqV7O9ZXMkg7JW6vmY+U/T8irJ1Hrx/0YHuBf2y9ufoOfEe5lhEkU81BXSAu kiSW7AWjQhdt7aHIRdHBDX2L9I9Z04280x+5ECyxxKt7CkxKIAmr5Glryn2FE58+E7ga X/DrQw58/0Myn4Lw75SzZkJosPR1mRA+Ljk0Oz7S/twThSXqU87X6SKMqOrtktiLWNAl hBDqU5kc3qHKsfViJW49mS0JFX3snFrs0AHoouRwQQNiJ7Ul04U3Nnn/5CE3Q5XZGSv5 6ZeYYMnpt1zJ3TcKJr/p/rDfdgyTbLiC0HJ3n+7sy9oN7+46s5YphiLtk6EqCmTNYYDw yBvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706186239; x=1706791039; 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=w/8P03y0gIOgiGCcOtW8CKbm2M0HUIblwn8rbFoZDFY=; b=bqj4So52EkI2rPVkHBC4/zn8C7NhLgUGNVp0aEBnC6Mbhi5CaXr/iRbycngSoStc1Z d54/g/k6IzvDMSSXezWRzlLZ1WGXSrHF1c+iKO2o7Y1ZanbmC7Xm7kyigJZW1O7fUW+1 gBOGJCbQ8TtiyttT0GSLCn3lUcbRTOFMGr0AKkrpe5KYpAkxXZ1cliZ0NOLRt2YlMczN i+u4XGtPNaOtsbPknwXhsPAOYJFfx4psVta1tXJnGf37t2XGaowcOx2FFM0gmC6MlSbD uZIkGsB2JnGaOX0EkkOi9D73234JCYaZq239JcGe1953uQmrVVoO/3untOF2pV8T0ZRN Pukw== X-Gm-Message-State: AOJu0YwlKcp+wE9F6ZTHDV8b1y6WAj+T7C9iApG2pMHGbaxKzo4cIPpQ T4tz+tUhHARm1fHYXBel9REgKgHmg8KBBBKTBEvDf55tQOiGchWrTYxDEU0q2yrWGbuLOJiaitI 3KV+v44NHGlYzYADod6++Bq0HvYBLOzRX7ecX X-Received: by 2002:a67:b906:0:b0:46a:efb9:8d16 with SMTP id q6-20020a67b906000000b0046aefb98d16mr511164vsn.64.1706186238360; Thu, 25 Jan 2024 04:37:18 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240124-alice-mm-v1-0-d1abcec83c44@google.com> <20240124-alice-mm-v1-2-d1abcec83c44@google.com> <070574cb-8d7f-4fe7-9826-cec6110168ff@app.fastmail.com> In-Reply-To: <070574cb-8d7f-4fe7-9826-cec6110168ff@app.fastmail.com> From: Alice Ryhl Date: Thu, 25 Jan 2024 13:37:07 +0100 Message-ID: Subject: Re: [PATCH 2/3] rust: add typed accessors for userspace pointers To: Arnd Bergmann Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Kees Cook , Alexander Viro , Andrew Morton , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Christian Brauner Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 25, 2024 at 1:27=E2=80=AFPM Arnd Bergmann wrote= : > > On Wed, Jan 24, 2024, at 12:20, Alice Ryhl wrote: > > +unsigned long > > rust_helper_copy_from_user_unsafe_skip_check_object_size(void *to, > > const void __user *from, unsigned long n) > > +{ > > + unsigned long res; > > + > > + might_fault(); > > + instrument_copy_from_user_before(to, from, n); > > + if (should_fail_usercopy()) > > + return n; > > + res =3D raw_copy_from_user(to, from, n); > > + instrument_copy_from_user_after(to, from, n, res); > > + return res; > > +} > > +EXPORT_SYMBOL_GPL(rust_helper_copy_from_user_unsafe_skip_check_object_= size); > > + > > +unsigned long > > rust_helper_copy_to_user_unsafe_skip_check_object_size(void __user *to, > > const void *from, unsigned long n) > > +{ > > + might_fault(); > > + if (should_fail_usercopy()) > > + return n; > > + instrument_copy_to_user(to, from, n); > > + return raw_copy_to_user(to, from, n); > > +} > > +EXPORT_SYMBOL_GPL(rust_helper_copy_to_user_unsafe_skip_check_object_si= ze); > > These functions are almost identical to the ones in > lib/usercopy.c for !defined(INLINE_COPY_TO_USER). > > That version has an extra memset() after a partial > copy_from_user(), and you probably want to have the > same thing here for consistency. > > I think ideally we should only have one out-of-line copy > of these two functions and have that one shared between > rust and architectures that want the C version out of line > as well. I had a bit of trouble figuring out all of the copy_[to/from]_user methods that are available. I was hoping that a better solution would be available, and it sounds like one is. Is _copy_from_user always available as an exported symbol? If it's always available and skips the check, then I can just use that. I don't think the memset matters for my case. Otherwise, I can add a helper in rust/helpers.c that wraps _copy_from_user only when INLINE_COPY_FROM_USER is defined, and call the helper in those cases, and otherwise call the exported symbol directly. (I need an exported symbol to call into C from Rust.) Would that make sense? Alice