Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp919924ybt; Wed, 1 Jul 2020 13:26:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweA8Sw1fMEfJy7eGj182U099vfnFpY/dK3zi/uau6jG2wbMbLQTZDzRXLqoQp/ZdLj5scu X-Received: by 2002:a50:e047:: with SMTP id g7mr30404946edl.290.1593635186281; Wed, 01 Jul 2020 13:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593635186; cv=none; d=google.com; s=arc-20160816; b=imyYlgIWmt4cL0/I8yyZ+lZ6F3DNPZKowYuq9EqaqxgOd5Fa6YmESMmBo8hkifaM3a aoUb2pKpfCQC2VAGdK4efKNC583oil8I+x70FZGQu4d0dXFIqa4pvq9gjludHnPD4H+8 sc9GH15Y+7onaqkRqXCvthnnJXQAlyv1NpOs7/IqjiOQAtvCUNEjD6xejSCPsfRqaF6/ gIqxbepHh70qtH+xN4EJkk4Ug2+WFC+QM6oT4+nutpj8pXGSH2UdEl+MBFdIx3oC7fIY 98taQuz8ojftRMswtfileIm/sifXeNc7n7BLc+2O6V//UYDEuryYczJAaE806/2sCbyw RSFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ksD9QkiHR08Ohmph9dxydHMFrxrcmluqn9uR39dpkfY=; b=cIWH2t3dfasGFxUSPFIzSwR97Ehi/H5sedgT4N13uOu/R9a8bhNJFkQxEjtIiM2b2v Woa+mF/nD76ylrD/7iQfPLgQE7comidAXeUKq8DrUdNLkGxxxdRdj4GC4cnRIufvnRpx KTEobV/K+IjoAITkoSF2RMzo0SVvl5r6LUCWc4kATqPrriPvwF0eQBM1xjRGE8cLFhor llrcBtA1nFdbgc/ISoteg4jUAkRjRnLmTfaelhKysBzpQ3kgk2CdA0FD/BmGOTsgzvkA jHBG2HWWY1uOumnuSnO2Cn8hOq4uhIqGS1RQOpkRN+qKrijElxtO2y8zlj+YAsV13Cuj J3RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="D3O/QeKO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt5si5938919ejc.335.2020.07.01.13.26.03; Wed, 01 Jul 2020 13:26:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="D3O/QeKO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726643AbgGAUZ4 (ORCPT + 99 others); Wed, 1 Jul 2020 16:25:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726049AbgGAUZ4 (ORCPT ); Wed, 1 Jul 2020 16:25:56 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF408C08C5C1 for ; Wed, 1 Jul 2020 13:25:55 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id d17so14103264ljl.3 for ; Wed, 01 Jul 2020 13:25:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ksD9QkiHR08Ohmph9dxydHMFrxrcmluqn9uR39dpkfY=; b=D3O/QeKOoId9j6oa3Hw9jrnKy0i1WaeBcGi9fiegINnzMRXt6ngpEAYI/VVFtM6xlj Xvcm4mEza5AiPsYyfUR93FPot5Yh0vJDjuB8u2CBQfYcoiOKIrp4XZB1STOUoW1OBc/8 EIlisbBKdCE+vG7AcJo0OU9W6UCzrJvFid23E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ksD9QkiHR08Ohmph9dxydHMFrxrcmluqn9uR39dpkfY=; b=Jeqwgf1hR7R6ytrevLl/QpOLabWFSR9qIOJJ66kyXcSsWXPvaIvWyBRByOAbfO8j0I cnO0sLhorfqxR0wAruy63Hto/HXowQP59O3BW6ppTphbe7+JzE/G51tgU21dqsSapnG+ 5m2tcl5JWWpDBDdvfMNp+k2yq591Vuw3vTl+7zJYtQEfTHq7NwsaKBUKdofJqQvgSpqH GwDLk7mYiJGHJzD+7pYMNUGNE9b1HHGQBTBKsQ9fGNvs4vc8RxpVUTzwNDuMf/hXOsdl tXsOOuvNgIAzLXjcIphvpXGVwtCeZ+v+0vV1nhgLy96uiPCxCzqAOrzD0EVippXW4w12 mBmw== X-Gm-Message-State: AOAM530sfsCJ9loo+2aB1Ydej1HEVp7UqBeF7GLUvjf4c22ikYN9JS6R S7bYY0slZNKWURke/+ziwlnvFPEuin0= X-Received: by 2002:a2e:8747:: with SMTP id q7mr13198125ljj.459.1593635153975; Wed, 01 Jul 2020 13:25:53 -0700 (PDT) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com. [209.85.208.182]) by smtp.gmail.com with ESMTPSA id 203sm2188363ljf.14.2020.07.01.13.25.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Jul 2020 13:25:53 -0700 (PDT) Received: by mail-lj1-f182.google.com with SMTP id d17so14103131ljl.3 for ; Wed, 01 Jul 2020 13:25:52 -0700 (PDT) X-Received: by 2002:a2e:9c92:: with SMTP id x18mr9204172lji.70.1593635152418; Wed, 01 Jul 2020 13:25:52 -0700 (PDT) MIME-Version: 1.0 References: <20200701184131.GI2786714@ZenIV.linux.org.uk> <20200701195914.GK2786714@ZenIV.linux.org.uk> In-Reply-To: <20200701195914.GK2786714@ZenIV.linux.org.uk> From: Linus Torvalds Date: Wed, 1 Jul 2020 13:25:36 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: objtool clac/stac handling change.. To: Al Viro , Christophe Leroy , Michael Ellerman Cc: Josh Poimboeuf , Peter Zijlstra , "the arch/x86 maintainers" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 1, 2020 at 12:59 PM Al Viro wrote: > > On Wed, Jul 01, 2020 at 12:04:36PM -0700, Linus Torvalds wrote: > > > > That's actually for the access granting. Shutting the access down ends > > up always doing the same thing anyway.. > > #define user_read_access_end prevent_current_read_from_user > #define user_write_access_end prevent_current_write_to_user > static inline void prevent_current_read_from_user(void) > { > prevent_user_access(NULL, NULL, ~0UL, KUAP_CURRENT_READ); > } > > static inline void prevent_current_write_to_user(void) > { > prevent_user_access(NULL, NULL, ~0UL, KUAP_CURRENT_WRITE); > } > > and prevent_user_access() has instances that do care about the direction... Go and look closer. There are three cases: (a) the 32-bit book3s case. It looks like it cares, but when you look closer, it ends up not caring about the read side, and saving the "which address to I allow user writes to" in current->thread.kuap (b) the nohash 32-bit case - doesn't care (c) the 64-bit books case - doesn't care So yes, in the (a) case it does make a difference between reads and writes, but at least as far as I can tell, it ignores the read case, and has code to avoid the unnecessary "disable user writes" case when there was only a read enable done. Now, it's possible that I'm wrong, but the upshot of that is that even on powerpc, I think that if we just made the rule be that "taking a user exception should automatically do the 'user_access_end()' for us" is trivial. But I'll add the powerpc people to the list too. And the arm64 people too, although it looks like they still haven't actually made the uaccess_disable() logic visible as user_access_begin/end and the unsafe_xyz code, so they'd not be impacted. Christophe/Michael: the discussion is that I'd actually want to change the "exception on user access" case to do the user_access_end() automatically, so that you can write code like if (!user_access_begin(...)) goto out; unsafe_get_user(..., out); unsafe_get_user(..., out); user_access_end(); .. all is good, use the value we got.. return 0; out: return -EFAULT; and use the same error label for both the "user_access_begin() failed" _and_ for the "oops, the access faulted". Right now the code needs to explicitly do the user_access_end() handling manually if one of the accesses fault. See for example fs/readdir.c, which has that efault_end: user_write_access_end(); efault: buf->result = -EFAULT; return -EFAULT; pattern of two different error targets several times. I'd like to avoid that user_{read_,write_,}access_end() case for the error handling entirely. It's extra complexity. I checked every single non-arch user, and for all of them it was just extra work (eg i915 driver, readdir, select, etc) The only case it wasn't an extra bother was the lib/strn{cpy,len}_from_user() cases, but that was because I literally organized the code to call a helper function be called in such a way that it always did the right thing. Linus