Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB185C7619A for ; Tue, 21 Mar 2023 17:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230025AbjCURvD (ORCPT ); Tue, 21 Mar 2023 13:51:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230141AbjCURu6 (ORCPT ); Tue, 21 Mar 2023 13:50:58 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 739F451C80 for ; Tue, 21 Mar 2023 10:50:53 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id eh3so62907771edb.11 for ; Tue, 21 Mar 2023 10:50:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1679421051; 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=jbTuKKPTGahowbJdCxJIAaT7lPuVx9AJJeoBmZ4Lmh4=; b=Vweh5rdFSwvlaLqVrE58+BS3C7MgBsraIxL5PiDQxkSwGUwgpM2x+imMlFOEuwDsPT Rvlt1JO5EsR7avYj9t3IGMfnMG9v3rzBE4p3jtxKgIzHWRZ96VElYq9CyxQaFCHEdEJD 3FoxRdUGs9+ZEch/L388ViBE+Cqu2v5DgVBSU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679421051; 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=jbTuKKPTGahowbJdCxJIAaT7lPuVx9AJJeoBmZ4Lmh4=; b=ce6pEGTUDN6u3rl/e0CNyhxtqHV82QkPjG5zEDx4rUcQk8qGVEuOUEH+O8ArSnBu52 35OnMZmDPbF+Ow7UAKu96mlahWOIctd6CRuxFszX/Mb4AKenziGDUtoy8QdPafB5r76A ixLc+8JtOiCqJLuW/mkVW7ApbmP9AQCL12672fRJse8sUS0elyBvD8hPe15yJDBvnV+o ZhFX9ZwSMRil5TEbjYo5Se8sKlxWLjO4DvZS41BXNQcVZqS5VelyOxMXoTK34yT8TNlq COyxvXLK0fJLMr5aGP+OAaQtnOnG+Wi42R9rP2MMkcdTSuzKvFuFdNmcsiIWyVe0fuXU 81DQ== X-Gm-Message-State: AO0yUKXRv08qkI/VLUGqGPlolFT93ER9eMG4JDG3gUg/W5jIDTlJfAn4 bo2vYrRnK7+RL2+b16nvd5BgeQHg3dOo6Ejyi0GQBw== X-Google-Smtp-Source: AK7set+adbFrrDIuMAo3yWpAfK+wcV3cG9YwbvPiqGOYyNkunwSvx7T03K94A1QjgAA2TRwH74sZbw== X-Received: by 2002:a17:907:c28f:b0:92b:e1ff:be30 with SMTP id tk15-20020a170907c28f00b0092be1ffbe30mr3797276ejc.4.1679421051508; Tue, 21 Mar 2023 10:50:51 -0700 (PDT) Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com. [209.85.208.47]) by smtp.gmail.com with ESMTPSA id mj4-20020a170906af8400b008ca8b62cda6sm6207829ejb.177.2023.03.21.10.50.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Mar 2023 10:50:50 -0700 (PDT) Received: by mail-ed1-f47.google.com with SMTP id x3so62890578edb.10 for ; Tue, 21 Mar 2023 10:50:50 -0700 (PDT) X-Received: by 2002:a17:907:9b03:b0:932:da0d:9375 with SMTP id kn3-20020a1709079b0300b00932da0d9375mr2314988ejc.4.1679421050440; Tue, 21 Mar 2023 10:50:50 -0700 (PDT) MIME-Version: 1.0 References: <20230321122514.1743889-1-mark.rutland@arm.com> <20230321122514.1743889-4-mark.rutland@arm.com> In-Reply-To: <20230321122514.1743889-4-mark.rutland@arm.com> From: Linus Torvalds Date: Tue, 21 Mar 2023 10:50:33 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 3/4] arm64: fix __raw_copy_to_user semantics To: Mark Rutland Cc: linux-kernel@vger.kernel.org, agordeev@linux.ibm.com, aou@eecs.berkeley.edu, bp@alien8.de, catalin.marinas@arm.com, dave.hansen@linux.intel.com, davem@davemloft.net, gor@linux.ibm.com, hca@linux.ibm.com, linux-arch@vger.kernel.org, linux@armlinux.org.uk, mingo@redhat.com, palmer@dabbelt.com, paul.walmsley@sifive.com, robin.murphy@arm.com, tglx@linutronix.de, viro@zeniv.linux.org.uk, will@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 21, 2023 at 5:25=E2=80=AFAM Mark Rutland = wrote: > > For some combinations of sizes and alignments __{arch,raw}_copy_to_user > will copy some bytes between (to + size - N) and (to + size), but will > never modify bytes past (to + size). > > This violates the documentation in , which states: > > > If raw_copy_{to,from}_user(to, from, size) returns N, size - N bytes > > starting at to must become equal to the bytes fetched from the > > corresponding area starting at from. All data past to + size - N must > > be left unmodified. Hmm. I'm not 100% sure we couldn't just relax the documentation. After all, the "exception happens in the middle of a copy" is a special case, and generally results in -EFAULT rather than any indication of "this is how much data we filled in for user space". Now, some operations do *try* to generally give partial results (notably "read()") even in the presence of page faults in the middle, but I'm not entirely convinced we need to bend over backwards over this. Put another way: we have lots of situations where we fill in partial user butffers and then return EFAULT, so "copy_to_user()" has at no point been "atomic" wrt the return value. So I in no way hate this patch, and I do think it's a good "QoI fix", but if this ends up being painful for some architecture, I get the feeling that we could easily just relax the implementation instead. We have accepted the whole "return value is not byte-exact" thing forever, simply because we have never required user copies to be done as byte-at-a-time copies. Now, it is undoubtedly true that the buffer we fill in with a user copy mus= t (a) be filled AT LEAST as much as we reported it to be filled in (ie user space can expect that there's no uninitialized data in any range we claimed to fill) (b) obviously never filled past the buffer size that was given But if we take an exception in the middle, and write a partial aligned word, and don't report that as written (which is what you are fixing), I really feel that is a "QoI" thing, not a correctness thing. I don't think this arm implementation thing has ever hurt anything, in other words. That said, at some point that quality-of-implementation thing makes validation so much easier that maybe it's worth doing just for that reason, which is why I think "if it's not too painful, go right ahead" is fine. Linus