Received: by 10.223.164.202 with SMTP id h10csp653721wrb; Mon, 6 Nov 2017 13:02:46 -0800 (PST) X-Google-Smtp-Source: ABhQp+TqXk4CtPRWcDZ7wmw/hjYZvS0kaNOC6HV3jq/1O9qKu8i6PnGKsEHd2ZxoOrWZ5WCRH4Up X-Received: by 10.84.233.12 with SMTP id j12mr15580279plk.420.1510002166100; Mon, 06 Nov 2017 13:02:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510002166; cv=none; d=google.com; s=arc-20160816; b=ETsndcvwYeRMwW9yzsAV54gM9NCRa4D2YdeLZhcngVujvpW4OX6FekQ+DOwb0rC9Fk 2x1lL2H//39NgyKFCjxI5xmlhqMckszdxUFDMLVIdCqL1LJa8pKnLwuCXRRs2aalyR+a ddmEiz2/VTNesco6vtf3hxJ1JH4z0b/ipSsuU5KKHj8VMjwUv49FuXD6nnVWPZnlCZ4P sRb+ae2NjMgUmR3RvyMJNS71CacOa5TjyAvrZ2Sn3vVKl6zz4FY+Tmgd8yND9D2PX9he enNVX0gfXSMvCOsRExDc5uInDdZl3AuvYTUZR1jkI/1DM1jhSy1QwlHYJoBlZbOZqyuv Q8AA== 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:references:cc:to:subject:from:arc-authentication-results; bh=JbuUt6eyI8radUbD2J665lc1as+fa0xfZyMGM/eMm3s=; b=NY4TK81MI33U75SixIHUckcczdZkSC8hxMAPTEc4k6fc0A2FT5c2UbNznN9y3Rvhi5 9lTRWrPjOAZoJg2Y+FcUaxlTIBk7KxQMDvtwym7ECh1NkVuwoN3T93XfwNls8qr4vfPx ShMOHgZVoA8ZeoYGd0Tdedc1BDyvSR4FCEPr8sGDpVQ5NL5rKLg9EH1hNj0IAAn7pz7C QT8dHnHMbD5hFCRBz0267yoRDshSlyZIUOmdXoP6vFRCaiQBdJ4ES4eJiAovW8OaPfK2 3QXNsH2FS3z6rEtdoLb9uP5WdIeOngxgJvob2MmGONBkxMKuM61JJjMNjgNOVk6KgWiV qpSQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o2si11667174pgp.46.2017.11.06.13.02.32; Mon, 06 Nov 2017 13:02:46 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933159AbdKFUiM (ORCPT + 95 others); Mon, 6 Nov 2017 15:38:12 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:49105 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932796AbdKFUiL (ORCPT ); Mon, 6 Nov 2017 15:38:11 -0500 Received: by mail-pg0-f67.google.com with SMTP id v78so9151601pgb.5 for ; Mon, 06 Nov 2017 12:38:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=JbuUt6eyI8radUbD2J665lc1as+fa0xfZyMGM/eMm3s=; b=aA3g08HYCuXApqfQWi0Uvzx/hmQr07AYj4JJnlqkim3OWjwHW+SyKhRV/z4dqacohR X1lsdTJ08WsyunPM/+5esFTOrdZJmxPK2AegY+hNVbHN61itsalqfsNT7cSxct2kbcjV iUkFuTSto9NtXu6kTD6yqjNVKvs1OOV+3T6rnPgdoziEmDV4NSyMGw9Ep9m++Lc+wnPW MhL2ar0XGJ8wWKspfPq5gC3WFTKD3TRoENxFHPESl2uySqzUEWoaRA0KhuZ+MXnfpDPT ZrgiJF3lSX4WxpkEy2iBwo8ZI4hDOlMS9yTQNuWNax5EDr+BrDb9atsijv5DrLsPVENU K7UA== X-Gm-Message-State: AMCzsaXgRJ1zPXOcG2BoW0pWrkkBY3ClpZnuu7hhJRXlw0m888YPVE8T E0UCnWRuO5GEdwYXQ+aVuD5usg== X-Received: by 10.98.65.11 with SMTP id o11mr17761776pfa.86.1510000690409; Mon, 06 Nov 2017 12:38:10 -0800 (PST) Received: from ?IPv6:2601:602:9802:a8dc::e174? ([2601:602:9802:a8dc::e174]) by smtp.gmail.com with ESMTPSA id k8sm21933825pgt.22.2017.11.06.12.38.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 12:38:09 -0800 (PST) From: Laura Abbott Subject: Re: [RFC PATCH 2/2] x86: Allow paranoid __{get,put}_user To: Kees Cook Cc: kernel-hardening@lists.openwall.com, LKML , Mark Rutland , X86 ML References: <20171103230426.19114-1-labbott@redhat.com> <20171103230426.19114-2-labbott@redhat.com> Message-ID: <228e1cbb-ec61-b54a-4093-2d377e90ca6b@redhat.com> Date: Mon, 6 Nov 2017 12:38:08 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/03/2017 05:14 PM, Kees Cook wrote: > On Fri, Nov 3, 2017 at 4:04 PM, Laura Abbott wrote: >> __{get,put}_user calls are designed to be fast and have no checks, >> relying on the caller to have made the appropriate calls previously. >> It's very easy to forget a check though, leaving the kernel vulnerable >> to exploits. Add an option to do the checks and kill the kernel if it >> catches something bad. >> >> Signed-off-by: Laura Abbott >> --- >> This is the actual implemtation for __{get,put}_user on x86 based on >> Mark Rutland's work for arm66 >> lkml.kernel.org/r/<20171026090942.7041-1-mark.rutland@arm.com> >> >> x86 turns out to be easier since the safe and unsafe paths are mostly >> disjoint so we don't have to worry about gcc optimizing out access_ok. >> I tweaked the Kconfig to someting a bit more generic. >> >> The size increase was ~8K in text with a config I tested. > > Specifically, this feature would have caught the waitid() bug in 4.13 > immediately. > >> --- >> arch/x86/Kconfig | 3 +++ >> arch/x86/include/asm/uaccess.h | 11 ++++++++++- >> security/Kconfig | 11 +++++++++++ >> 3 files changed, 24 insertions(+), 1 deletion(-) >> >> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig >> index 2fdb23313dd5..10c6e150a91e 100644 >> --- a/arch/x86/Kconfig >> +++ b/arch/x86/Kconfig >> @@ -261,6 +261,9 @@ config RWSEM_XCHGADD_ALGORITHM >> config GENERIC_CALIBRATE_DELAY >> def_bool y >> >> +config ARCH_HAS_PARANOID_UACCESS >> + def_bool y >> + >> config ARCH_HAS_CPU_RELAX >> def_bool y >> >> diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h >> index d23fb5844404..767febe1c720 100644 >> --- a/arch/x86/include/asm/uaccess.h >> +++ b/arch/x86/include/asm/uaccess.h >> @@ -132,6 +132,13 @@ extern int __get_user_bad(void); >> #define __inttype(x) \ >> __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL)) >> >> + >> +#define verify_uaccess(dir, ptr) \ >> +({ \ >> + if (IS_ENABLED(CONFIG_PARANOID_UACCESS)) \ >> + BUG_ON(!access_ok(dir, (ptr), sizeof(*(ptr)))); \ >> +}) >> + >> /** >> * get_user: - Get a simple variable from user space. >> * @x: Variable to store result. >> @@ -278,6 +285,7 @@ do { \ >> typeof(ptr) __pu_ptr = (ptr); \ >> retval = 0; \ >> __chk_user_ptr(__pu_ptr); \ >> + verify_uaccess(VERIFY_WRITE, __pu_ptr); \ >> switch (size) { \ >> case 1: \ >> __put_user_asm(x, __pu_ptr, retval, "b", "b", "iq", \ >> @@ -293,7 +301,7 @@ do { \ >> break; \ >> case 8: \ >> __put_user_asm_u64((__typeof__(*ptr))(x), __pu_ptr, \ >> - retval, \ errret); \ >> + retval, errret); \ >> break; \ >> default: \ >> __put_user_bad(); \ > > Which tree is this against? I don't see the weird line break in my tree? > Uggggh I meant to fold this into the previous patch. >> @@ -359,6 +367,7 @@ do { \ >> typeof(ptr) __gu_ptr = (ptr); \ >> retval = 0; \ >> __chk_user_ptr(__gu_ptr); \ >> + verify_uaccess(VERIFY_READ, __gu_ptr); \ >> switch (size) { \ >> case 1: \ >> __get_user_asm(x, __gu_ptr, retval, "b", "b", "=q", \ > > Does __put/get_user_size_ex() need additions too? (And does > put/get_user_ex() lack access_ok() checks as-is? Looks like the users > are have access_ok() checks, but that naming really shouldn't be > aliased to "put/get_user_ex" -- otherwise it gives the impression it's > doing access_ok() checks...) > Possibly? A better approach might be to add the check to uaccess_try which is where all the users already are. The users of these APIs are pretty limited and I doubt they'd get used randomly. Thanks, Laura From 1583098938202506226@xxx Sat Nov 04 01:59:57 +0000 2017 X-GM-THRID: 1583087968601748752 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread