Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp929354ybl; Fri, 24 Jan 2020 12:08:57 -0800 (PST) X-Google-Smtp-Source: APXvYqwza5B5ae3gMulL4xaoa/u8v3EaAYyyO4F7YLWBBc9xu3U92WPORxL4nwodFCpUajDnna5r X-Received: by 2002:a9d:6a47:: with SMTP id h7mr4245218otn.244.1579896537645; Fri, 24 Jan 2020 12:08:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579896537; cv=none; d=google.com; s=arc-20160816; b=uKdRo2o+DsZ8YOFEC3BTHyVMOj5NNXVbD2pXKM6CbNAO0cZ98cCNqp3ZBPUchSppNb QMvLXBwksat6HKXA3k0krjS+VOMuA7CXLZcq0hItOqoqVrDYEW1eh4DonzS0cwpXRiG2 d+hSXhYB+aL+f6WNcfsC4Rrc8I68xSJy0w+zL3YezZWPchIm3MV6c3Cg6iKFN7gnGXdc OsK98zzmPhv5LD2nXBfhPJ59yRmWfwcxoo4/gh1PQYF1rSWF7ZRPTQWjE8XZPV9DP0vq LQ4KZThCUjcw9+cjdJsQa+mudWy8l0uh94gcAkbOz47reL0Z4BM+6sShvRPK3MjnJka9 +9Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=FHdRJ1lym9x5LZH3JKxzccvEq6M9sGBs3OTmqNRLhTU=; b=aD4HmrS5B8IrGvIIBlqcfHTtADmYKsfoBh4gbmOORNm/jP7KYP7wN0tE/EAc1KIF9d 1vmwrmXeYPat1wR26CP94vowRvP7KY1esNgbHBjeXTuxb6RptHEUoFIncVCuh3KHKdAR 1nEhp7VFkXXBW237p5m3Dh2XGz4T6ZDj51kJ+vAoBiEsRH+cbfdQaqdFgHOnvoLlru4z I8QXSv3L0a3SjmgFA0x1O6NfnccYFqn9A06OY3grmeTNn0E6oU1f3ZgzKoGblrCDxvQJ oluLtz1npoqTkMeCjDU9c2s73WyoU0IJyo2AcMI5oc5d/CeZmZYuTeerBi0QAd3DUrzp C3MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=iiu4nggJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f14si3509349otf.178.2020.01.24.12.08.28; Fri, 24 Jan 2020 12:08:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=iiu4nggJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392047AbgAXLkc (ORCPT + 99 others); Fri, 24 Jan 2020 06:40:32 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:10076 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403843AbgAXLk0 (ORCPT ); Fri, 24 Jan 2020 06:40:26 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 483xyt3Jbyz9tyMg; Fri, 24 Jan 2020 12:40:22 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=iiu4nggJ; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id A3I6opIEV_tl; Fri, 24 Jan 2020 12:40:22 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 483xyt27bmz9tyMf; Fri, 24 Jan 2020 12:40:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1579866022; bh=FHdRJ1lym9x5LZH3JKxzccvEq6M9sGBs3OTmqNRLhTU=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=iiu4nggJtlejyS9CxTCWd166SJF9J7eVXuwRZ7M2gotO68hUK81m+MR2Tstk3ho8B Rj9fXdhonGjq/7IdTo1GHGLsriWmDEEd0f4c2HcS4bPl+9p+eVKJ1QKA/pX/XYHPtq QQIRjBIznCVLXgOan515E+eWZeriwxtYhT7tVKTQ= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 885948B858; Fri, 24 Jan 2020 12:40:23 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id Rd4xOECJWD9L; Fri, 24 Jan 2020 12:40:23 +0100 (CET) Received: from [172.25.230.111] (po15451.idsi0.si.c-s.fr [172.25.230.111]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 514BB8B84A; Fri, 24 Jan 2020 12:40:23 +0100 (CET) Subject: Re: [PATCH v2 6/6] powerpc: Implement user_access_begin and friends To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org References: <12a4be679e43de1eca6e5e2173163f27e2f25236.1579715466.git.christophe.leroy@c-s.fr> <2a20d19776faba4d85dbe51ae00a5f6ac5ac0969.1579715466.git.christophe.leroy@c-s.fr> <87iml2idi9.fsf@mpe.ellerman.id.au> <87ftg6icc8.fsf@mpe.ellerman.id.au> From: Christophe Leroy Message-ID: <0c2855c2-a6d6-6b35-7f69-f55add58dfb8@c-s.fr> Date: Fri, 24 Jan 2020 12:40:23 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <87ftg6icc8.fsf@mpe.ellerman.id.au> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 23/01/2020 à 13:31, Michael Ellerman a écrit : > Michael Ellerman writes: >> Christophe Leroy writes: >>> Today, when a function like strncpy_from_user() is called, >>> the userspace access protection is de-activated and re-activated >>> for every word read. >>> >>> By implementing user_access_begin and friends, the protection >>> is de-activated at the beginning of the copy and re-activated at the >>> end. >>> >>> Implement user_access_begin(), user_access_end() and >>> unsafe_get_user(), unsafe_put_user() and unsafe_copy_to_user() >>> >>> For the time being, we keep user_access_save() and >>> user_access_restore() as nops. >> >> That means we will run with user access enabled in a few more places, but >> it's only used sparingly AFAICS: >> >> kernel/trace/trace_branch.c: unsigned long flags = user_access_save(); >> lib/ubsan.c: unsigned long flags = user_access_save(); >> lib/ubsan.c: unsigned long ua_flags = user_access_save(); >> mm/kasan/common.c: unsigned long flags = user_access_save(); >> >> And we don't have objtool checking that user access enablement isn't >> leaking in the first place, so I guess it's OK for us not to implement >> these to begin with? > > It looks like we can implement them on on all three KUAP > implementations. > > For radix and 8xx we just return/set the relevant SPR. > > For book3s/32/kup.h I think we'd just need to add a KUAP_CURRENT case to > allow_user_access()? Can't do that, we don't want to keep the info in current->thread.kuap after user_access_save(), otherwise we might unexpectedly re-open access through an interrupt. And if we use KUAP_CURRENT case of prevent_user_access(), it means we'll read current->thread.kuap twice. So, just regenerate addr and end from the flags, and use allow_user_access() and prevent_user_access() as usual. I'll have it in v4 Christophe