From patchwork Tue Oct 2 13:12:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10623651 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0312314BD for ; Tue, 2 Oct 2018 13:13:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED16C2846C for ; Tue, 2 Oct 2018 13:13:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E00BA285C7; Tue, 2 Oct 2018 13:13:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C0EF2846C for ; Tue, 2 Oct 2018 13:13:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726689AbeJBT5F (ORCPT ); Tue, 2 Oct 2018 15:57:05 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37462 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727822AbeJBT4G (ORCPT ); Tue, 2 Oct 2018 15:56:06 -0400 Received: by mail-wr1-f65.google.com with SMTP id u12-v6so2172856wrr.4 for ; Tue, 02 Oct 2018 06:12:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hg72P0CosgRbWoaFLc14vzZ1X5hDU4dYtp5LLPrtPyY=; b=YxOsXrwelAI/lXWqUvyP80W002B/7n6YQbPrxkL3Y/miO7blJJ1EdFiyRBNCCwuumv LVsj+hqhdHZjOY9W8MhdK1bk6eCDfyjz930bJmURnf6BgQMurMXp2LPNMmBOo23+fUZK bFq3knuWoaKlq+KJWir7KTX3naHfXXzSSp8PMJ+wrZA711u4/zKWOTjkyH6Zcnf7lM3X HVyooy564WzO4uvgji0Lb8fngQnuYXBqiLiC2s/b/R+py7YRH8VN5vGKUMcUa2NFUR9x 4we1MwOXrkCACvUvM7bAXHfluyXrVN2H6IKjodbIdeAACkgmslAF0UFZ8S67M8zgYfu6 VjGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hg72P0CosgRbWoaFLc14vzZ1X5hDU4dYtp5LLPrtPyY=; b=nTtplLM+BQ8rS7AqkUO0Y+nBRfQfkSfH3cm2z8QBSvjw3tkQgRnQDaZyyTMOLhlAo9 6eKgUsiEG2a6R6ZqUWEhzX+xLcD2jYrcJ97gUX5/Ulk2IN5w79f3ZSMwTizwyzeNK5HK o4rYV/W+q1g8ouXo/H/+Dt38emIrRTvMsD6Tl0KPhOXRcYm3rNoA5evOfay9etjHmEq1 AONjI1tv9WcHADwPZj5apI20UHmSS8t40FLWq4QeaiXql/LUiPVwzNWotYpYTNoAbLxY 2lgEwx/PH05qIW9InHAZjSjQLsxm7JlbUCdcVZrVowgsV6Ir0TA55bSW8Ws2GtYM/4B1 IOpg== X-Gm-Message-State: ABuFfohN8c5lKuzPEXZU8jvRx8RJS2lNOuWEXF/aM/97RYYqiGuz1iDY f8xbdnna3eBbgC8M6pCQxherY4rnSeVqCw== X-Google-Smtp-Source: ACcGV63EvbNvms24ttmp368a2zKSU61XpI0aSwgZcGP8ZkkbdUH3S7LIgrnqug9JC04dDVPW2NeEoQ== X-Received: by 2002:adf:9792:: with SMTP id s18-v6mr11252530wrb.283.1538485967668; Tue, 02 Oct 2018 06:12:47 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id v10-v6sm17458681wrp.0.2018.10.02.06.12.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 06:12:47 -0700 (PDT) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya , Luc Van Oostenryck , Andrey Konovalov Subject: [PATCH v7 1/8] arm64: add type casts to untagged_addr macro Date: Tue, 2 Oct 2018 15:12:36 +0200 Message-Id: <6a951a9d1cd38eac1e49591f70e3cb9410349823.1538485901.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch makes the untagged_addr macro accept all kinds of address types (void *, unsigned long, etc.) and allows not to specify type casts in each place where it is used. This is done by using __typeof__. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/uaccess.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index e66b0fca99c2..2d6451cbaa86 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -102,7 +102,8 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long si * up with a tagged userland pointer. Clear the tag to get a sane pointer to * pass on to access_ok(), for instance. */ -#define untagged_addr(addr) sign_extend64(addr, 55) +#define untagged_addr(addr) \ + ((__typeof__(addr))sign_extend64((__u64)(addr), 55)) #define access_ok(type, addr, size) __range_ok(addr, size) #define user_addr_max get_fs From patchwork Tue Oct 2 13:12:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10623649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF11414BD for ; Tue, 2 Oct 2018 13:13:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3D772846C for ; Tue, 2 Oct 2018 13:13:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7BD1285C7; Tue, 2 Oct 2018 13:13:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 939302846C for ; Tue, 2 Oct 2018 13:13:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726156AbeJBT5B (ORCPT ); Tue, 2 Oct 2018 15:57:01 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:44114 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727943AbeJBT4H (ORCPT ); Tue, 2 Oct 2018 15:56:07 -0400 Received: by mail-wr1-f66.google.com with SMTP id 63-v6so2155400wra.11 for ; Tue, 02 Oct 2018 06:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Cq3vN6aPcQwtnG7Yk3tP2XwC690M9TeiFA6EGKo+spg=; b=wVK2wJsBGU5FIzxsuMJcgTdTL10q6LtoeL+UENspJKFgA0RDNTzi9Wn5gAyDr+6Szv RncY5kWukrU8NwSkp4uPffTL6eb+JtiBGH/Jp80QDfaMmzXGUpB7izMO5ZlGKrJ/c+NM S3mjkFvCJ3ABkch+sQLZcNPA/SdENdR9ieF/M8THE6aUPYbQYb7DD3n9cIvpFuI7qLT3 +ZUu1kES5j/a2JYULJs6Ry0XZ+RqRXQI2jOIg5lPqOT26QlkW3W+kKGlm1f1B+9coovo V0zbhgSer4xnymtNsXnnPFCfur591TOZxRATREyyigBwTz3+tXsZi3uIwP51Q2Zc36uq h/rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Cq3vN6aPcQwtnG7Yk3tP2XwC690M9TeiFA6EGKo+spg=; b=jOZfbEwJdRqd20kyimp80b9twBg/+9F85PwzEWLT61XTTYtNHgcxqDnUtyN7hC5AlR Fu2/LNzDIMbdr5yv9FnNnikziXoZGNQArLlLcOcMrXhE+0+pjXYgNhtfLjV5QjDDkj7H iS9m07lIWZK4imx9JjNIK+JxcL1yZ2SiFW+xgDabREGNKeqJugGqMafnxfhcfptP1v+D uIxxTlHkidB2003KSt35h0Ya1FTD1CpkJUJhIk63feiUlmLQrPuWhrLQNUvHzhPzP7/+ 463c0OA1XsQFYvKGoWYwPAI9NR5UPeWNfUGTgBwYBAgNzxQcZfJxleq3s+ZWFB7qf7EH x7rg== X-Gm-Message-State: ABuFfohn91NGCz1NCMO/UNAfBa4HSzC1cMRrJhT4055yQhZXCs4c3xR1 Mubsp8na9ZKAFnmC4c+j1Pl7OQ== X-Google-Smtp-Source: ACcGV62AocYuBthFf3RuZ7M7TITSn4vXXnPKZ8bb2eLezWn89dGEtVrCS/4KW1hgHo/fTVInkvsQ6Q== X-Received: by 2002:adf:db8e:: with SMTP id u14-v6mr10999323wri.217.1538485969081; Tue, 02 Oct 2018 06:12:49 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id v10-v6sm17458681wrp.0.2018.10.02.06.12.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 06:12:48 -0700 (PDT) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya , Luc Van Oostenryck , Andrey Konovalov Subject: [PATCH v7 2/8] uaccess: add untagged_addr definition for other arches Date: Tue, 2 Oct 2018 15:12:37 +0200 Message-Id: <1ff6af9a9ab1f716d0ecbfcfe6788a02e21b7480.1538485901.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To allow arm64 syscalls accept tagged pointers from userspace, we must untag them when they are passed to the kernel. Since untagging is done in generic parts of the kernel, the untagged_addr macro needs to be defined for all architectures. Define it as a noop for other architectures besides arm64. Signed-off-by: Andrey Konovalov --- include/linux/uaccess.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index efe79c1cdd47..c045b4eff95e 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -13,6 +13,10 @@ #include +#ifndef untagged_addr +#define untagged_addr(addr) addr +#endif + /* * Architectures should provide two primitives (raw_copy_{to,from}_user()) * and get rid of their private instances of copy_{to,from}_user() and From patchwork Tue Oct 2 13:12:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10623647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B53714BD for ; Tue, 2 Oct 2018 13:13:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90118285A4 for ; Tue, 2 Oct 2018 13:13:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 832042873C; Tue, 2 Oct 2018 13:13:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36523285A4 for ; Tue, 2 Oct 2018 13:13:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726710AbeJBT4w (ORCPT ); Tue, 2 Oct 2018 15:56:52 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35756 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727976AbeJBT4J (ORCPT ); Tue, 2 Oct 2018 15:56:09 -0400 Received: by mail-wm1-f66.google.com with SMTP id o18-v6so2163800wmc.0 for ; Tue, 02 Oct 2018 06:12:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UwxTkI+pYsHu40iHWOY4wB/R27fPZGDmoFBeZbslwgQ=; b=uOQ+FfmUC+RaS3QyuW/9cJe9RH7pk1ltGJ/08pMGtCZU0scrsbZfvGCfzNFlnYWeR5 g4Vr9xESUkQ3uzvvWZq0xdqiM4GWXtOzvpTeiJAGBAFrgtHYW5APJNvA76dSQYg6AQ6U +HnGxnOWKMtPLutPQOCuJNs520+lOBa8RK6H5554UVrF0vYcw9e7fDpm51uyEaclf9he mlrY9jl92q9OeuR3mYmCoOs+LQInROEeHRG03TikcJ97tIw0t2mAJ68JeLA3lwRgRJ8x Pq5kHnJz2EmX3aXhV7wv8Shr2/YuRwwklttZlbsqxMfB4W5wvp501g+TByqSV28przNS TNVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UwxTkI+pYsHu40iHWOY4wB/R27fPZGDmoFBeZbslwgQ=; b=uZfOzxxstKZmnUrNLgyw/K05XH4rp3Yy8UVBIztWjODG8qYFsUtbQ3HjLmGT11n+XL RxIa1pe7aXDrx/croYJDV4VN8F7iKTprp01KYttPH/ttw/NGdj5jPGatVju1J5EqtNdC uK1E34BaWEhv3miM+xHEYWZsQQQ8ZlFXLNjrzSTfybW3tlFGqIaAi1BkN8E+p8DTWRiA D+XHkR58dfVAit4zjGVtTbbGi6kjuQYe/4jrIH71uT9o1seFWTg20C1Yz37KHJkHivIK IuwErf35zsmSa1hepCGfE0H3NqZDHvXP6C8PqatG3Yd3ILZ93TwU+HJTRJ8nCLLzAO0s ZRLA== X-Gm-Message-State: ABuFfojtqw9HHKoWAVfLr5mX7F30UerGb3Uu17CVI19psTs+96OHhPxC akcxKYJ7VZ8X58WTKV9yWukIhA== X-Google-Smtp-Source: ACcGV622sDyFt3S8csEmXThpDBNFNMvaRauKoxqXv/A4k50G/uwAP10xj9S7JvVx/Gl6W/hzjmgNeA== X-Received: by 2002:a1c:d4b:: with SMTP id 72-v6mr1969892wmn.102.1538485970324; Tue, 02 Oct 2018 06:12:50 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id v10-v6sm17458681wrp.0.2018.10.02.06.12.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 06:12:49 -0700 (PDT) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya , Luc Van Oostenryck , Andrey Konovalov Subject: [PATCH v7 3/8] arm64: untag user addresses in access_ok and __uaccess_mask_ptr Date: Tue, 2 Oct 2018 15:12:38 +0200 Message-Id: <2b957e4f0a3133480dda9d9c8aeceb9b9d9378eb.1538485901.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP copy_from_user (and a few other similar functions) are used to copy data from user memory into the kernel memory or vice versa. Since a user can provided a tagged pointer to one of the syscalls that use copy_from_user, we need to correctly handle such pointers. Do this by untagging user pointers in access_ok and in __uaccess_mask_ptr, before performing access validity checks. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/uaccess.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 2d6451cbaa86..fa7318d3d7d5 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -105,7 +105,8 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long si #define untagged_addr(addr) \ ((__typeof__(addr))sign_extend64((__u64)(addr), 55)) -#define access_ok(type, addr, size) __range_ok(addr, size) +#define access_ok(type, addr, size) \ + __range_ok(untagged_addr(addr), size) #define user_addr_max get_fs #define _ASM_EXTABLE(from, to) \ @@ -237,7 +238,8 @@ static inline void uaccess_enable_not_uao(void) /* * Sanitise a uaccess pointer such that it becomes NULL if above the - * current addr_limit. + * current addr_limit. In case the pointer is tagged (has the top byte set), + * untag the pointer before checking. */ #define uaccess_mask_ptr(ptr) (__typeof__(ptr))__uaccess_mask_ptr(ptr) static inline void __user *__uaccess_mask_ptr(const void __user *ptr) @@ -245,10 +247,11 @@ static inline void __user *__uaccess_mask_ptr(const void __user *ptr) void __user *safe_ptr; asm volatile( - " bics xzr, %1, %2\n" + " bics xzr, %3, %2\n" " csel %0, %1, xzr, eq\n" : "=&r" (safe_ptr) - : "r" (ptr), "r" (current_thread_info()->addr_limit) + : "r" (ptr), "r" (current_thread_info()->addr_limit), + "r" (untagged_addr(ptr)) : "cc"); csdb(); From patchwork Tue Oct 2 13:12:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10623625 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F45D174E for ; Tue, 2 Oct 2018 13:12:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3C00288FC for ; Tue, 2 Oct 2018 13:12:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E78E72890A; Tue, 2 Oct 2018 13:12:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C82028985 for ; Tue, 2 Oct 2018 13:12:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728071AbeJBT4L (ORCPT ); Tue, 2 Oct 2018 15:56:11 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:35946 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727829AbeJBT4K (ORCPT ); Tue, 2 Oct 2018 15:56:10 -0400 Received: by mail-wr1-f67.google.com with SMTP id y16so2179045wrw.3 for ; Tue, 02 Oct 2018 06:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M+fzLalqRaXGFiw1By6nH8QQrYEhVoORFRhjy/6ZtCk=; b=g/5+TE8qrM0S966GF0ehpYeatmN6rBIDeIbCUA440M2nraTgJHSOOqRefWma3H2QFk db/TLUMgW+3DdtgV6yDyHfsewvdoZ7XQ0S1jqS57d41YAflXkP1pp9HlkbzYwNkS0JIY pRVdhsSySSV0TihlxSpRvVQSVaJywiekWjskRHndBNzF7BevnT1qmGTO4DaIhzYUXxry LRsUaYPgQ3TIeOamcd3WNyixCIR5UKwYktsOiGG1HrBcYgd/3s9nCOH/IZLWx8A6pH7v c1a8+L2HtBSCHGIVd4jnex5QRuAgpohMaN8a5DeTpNqK4l46AuDUGWCyxe5giES9UqQY RTdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M+fzLalqRaXGFiw1By6nH8QQrYEhVoORFRhjy/6ZtCk=; b=fS4Mzn364DE/lOT3k6+DbaQZcBxxYBZMLas7XyswCgXJg1cL3MxdUI5qhIm91ED82R QuJFsJCGA8rztI3d4Yyh8DMJjdFkiFN0E04Yb2DDs+qvOpAE3R/ou7Zq21uHeO3+vL2j TWETMEz2ZT7GHHJ/tpAE40AZH5yoNIhncj3tJ6mkHw9vG+4NffXqM52FRFj5I1BEMv/N RA/VGBUgi1S2TAYLc+JezYeHS+R77jIU6lefEQmUu1eLnH4QDhWhF9MzfbOz5Z8xE8WJ ouzhvX8Uqy7ElLVTvYnWdR7Tyi1O6jnK0Iltcaxn7W54Z7lg5cjMLMDYfy/cA8BQ/LQ9 qVnA== X-Gm-Message-State: ABuFfogfxuYGyibguKc+q73E5nr+fe1cbyBlhCVZ3IVLQbWcFLp8mxgL nJAzYkayk+3wSd11kRWYzQr6Ww== X-Google-Smtp-Source: ACcGV634rYLGlFVKrv5iDfl8Icy0xrHVGOhV9Puza2K4wNp0CAyWdiFG3gBDc0/36ZWC9rHQ4ru4hQ== X-Received: by 2002:adf:8022:: with SMTP id 31-v6mr8356555wrk.16.1538485971887; Tue, 02 Oct 2018 06:12:51 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id v10-v6sm17458681wrp.0.2018.10.02.06.12.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 06:12:50 -0700 (PDT) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya , Luc Van Oostenryck , Andrey Konovalov Subject: [PATCH v7 4/8] mm, arm64: untag user addresses in mm/gup.c Date: Tue, 2 Oct 2018 15:12:39 +0200 Message-Id: <405ee9e84a83178e762d8bac97dd1b36ea09074e.1538485901.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP mm/gup.c provides a kernel interface that accepts user addresses and manipulates user pages directly (for example get_user_pages, that is used by the futex syscall). Since a user can provided tagged addresses, we need to handle such case. Add untagging to gup.c functions that use user addresses for vma lookup. Signed-off-by: Andrey Konovalov --- mm/gup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 1abc8b4afff6..6f09132c654e 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -666,6 +666,8 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, if (!nr_pages) return 0; + start = untagged_addr(start); + VM_BUG_ON(!!pages != !!(gup_flags & FOLL_GET)); /* @@ -820,6 +822,8 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm, struct vm_area_struct *vma; vm_fault_t ret, major = 0; + address = untagged_addr(address); + if (unlocked) fault_flags |= FAULT_FLAG_ALLOW_RETRY; From patchwork Tue Oct 2 13:12:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10623645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3A4D14BD for ; Tue, 2 Oct 2018 13:13:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8E4D288C4 for ; Tue, 2 Oct 2018 13:13:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9578128931; Tue, 2 Oct 2018 13:13:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B5972890A for ; Tue, 2 Oct 2018 13:13:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726492AbeJBT4o (ORCPT ); Tue, 2 Oct 2018 15:56:44 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33576 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728058AbeJBT4M (ORCPT ); Tue, 2 Oct 2018 15:56:12 -0400 Received: by mail-wr1-f67.google.com with SMTP id e4-v6so2194037wrs.0 for ; Tue, 02 Oct 2018 06:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NvErLiPb7Dhi68E8otsA18THd2lbB+9b3/NhcG854Xk=; b=J3rqMQ+OwoWESxRlNUNZvjq3C/i5394uPASFBYI9muB/L1ZiyOZBCro1+FKtx6blgw Zf3QR0zbR9aBLw8k94HJn2BihJomkAwGXZ6D3IccQan79jH4+JXMjrtrO30iOwbiwlL7 ZXwh97DJrxJryJEPEhuLlgAGLLAKtiHeczVtcczOfqs5HYQ7W2vG5CxdrOSeUx2uSvN5 GAAUamfcPXwAaP0TYFJuhfKsE1NhlhzkhRgg8V0uSoEfQtqHCiPnIouALNbppfaPkHjL VYO3WaSNSHcsFRl7xSVGvwVKBnyNE6GtDLcbcOxwj/EAXF0Z2usZxGp1Hq2AoDKtY0gx DxAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NvErLiPb7Dhi68E8otsA18THd2lbB+9b3/NhcG854Xk=; b=PQYhdnHW9N+A3YUqO2Yef8Y6vbLjyrhH8AX3b+zprVwIqCXKwmIGDHZCYhoDk7ghYE spPuQqXGyaA/6E/dy50OnAzwWPQ0IP6rCpId4wHQRnxX11/rG83/PAC9P73LbXakYg3Q oQbRxRR2k/7QH4T6bDqU3VYWjfFwiROfCepe3wP3FotfU3QoqRgVjvtii1ocDgmjtEY7 SywDgG/uA2HpdJSt4nVMyZYkv0JRUDRc+Po60k5xDVFOukmOE/gSBh+T66Jj86fkfM97 4+83OTuB4+8Pz9xcIrhxGCb2iTg5ku7FljtwXu/1IHhu/lsQrEkkPs3EHT41jTg6gqkF u0Lg== X-Gm-Message-State: ABuFfoiX6X+CMyhUTOJ2tE9ZlUnzK2pBD4jO3IRx3yvr4AJZ9L3wqQ9M NQ0pfmDOtTLRnFz5K28sjx0T/Q== X-Google-Smtp-Source: ACcGV63nabJtbVmhZN2ucFxis2mJLsrnliWxzagWfRZDa1M/aDSkXCme9Zu5EuIB9WfhAKLrjz02yA== X-Received: by 2002:a5d:4101:: with SMTP id l1-v6mr6433311wrp.45.1538485973338; Tue, 02 Oct 2018 06:12:53 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id v10-v6sm17458681wrp.0.2018.10.02.06.12.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 06:12:52 -0700 (PDT) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya , Luc Van Oostenryck , Andrey Konovalov Subject: [PATCH v7 5/8] lib, arm64: untag addrs passed to strncpy_from_user and strnlen_user Date: Tue, 2 Oct 2018 15:12:40 +0200 Message-Id: <978d6bcda7f6cc9420d77b1155d54300e73a634d.1538485901.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP strncpy_from_user and strnlen_user accept user addresses as arguments, and do not go through the same path as copy_from_user and others, so here we need to handle the case of tagged user addresses separately. Untag user pointers passed to these functions. Signed-off-by: Andrey Konovalov --- lib/strncpy_from_user.c | 2 ++ lib/strnlen_user.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c index b53e1b5d80f4..97467cd2bc59 100644 --- a/lib/strncpy_from_user.c +++ b/lib/strncpy_from_user.c @@ -106,6 +106,8 @@ long strncpy_from_user(char *dst, const char __user *src, long count) if (unlikely(count <= 0)) return 0; + src = untagged_addr(src); + max_addr = user_addr_max(); src_addr = (unsigned long)src; if (likely(src_addr < max_addr)) { diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c index 60d0bbda8f5e..8b5f56466e00 100644 --- a/lib/strnlen_user.c +++ b/lib/strnlen_user.c @@ -108,6 +108,8 @@ long strnlen_user(const char __user *str, long count) if (unlikely(count <= 0)) return 0; + str = untagged_addr(str); + max_addr = user_addr_max(); src_addr = (unsigned long)str; if (likely(src_addr < max_addr)) { From patchwork Tue Oct 2 13:12:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10623627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED6FA13BB for ; Tue, 2 Oct 2018 13:12:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0A68288E4 for ; Tue, 2 Oct 2018 13:12:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEB0928931; Tue, 2 Oct 2018 13:12:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91ACB28961 for ; Tue, 2 Oct 2018 13:12:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728113AbeJBT4N (ORCPT ); Tue, 2 Oct 2018 15:56:13 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45279 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727942AbeJBT4N (ORCPT ); Tue, 2 Oct 2018 15:56:13 -0400 Received: by mail-wr1-f68.google.com with SMTP id q5-v6so2145410wrw.12 for ; Tue, 02 Oct 2018 06:12:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xOEYtA/I6Fm+wYElUl5x45bwyq3Cixn9jAS0SVOnGHY=; b=hapSsxwdWXwCXhX3cx/PcxUUNiBlkLbDk5Ol0GIiM68H9rsaDKFOhEppykmnJbSMIG hP4HvsnoWoqCLF1XH0klHSE3kJRDP7PzPV+P6sfrd5jZTa5O9wY0NHxHbg+ssowNWDAK jMZK0Qtbun2y4bsuxkmMQDRH3ZXywQU73104mMawS21UPnCx0hs79aj2FTAWAvr0G5Zk bxZmeY1y8kNyiwgFzrMFxb0Kd5/hqdAgiK5/yWb9dAnFsWl2bEa6+ntzVC/LqyX7KdsE qebdV3d2DvQAFlQK5j16Cw1+qqvmSmApY2GvOiRAmqs6XOLDd7R47nErQEM1ADlvsb3k CIGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xOEYtA/I6Fm+wYElUl5x45bwyq3Cixn9jAS0SVOnGHY=; b=gS+rYVsJsvsF1VPr4QZKoh9NuFM2wEulLDWnVfkKZXurDvV5lRiPKIV0Wa2+tN4Hvf W0yObNUOnNV87JamuItyapAGbUNvaxQ8CwlkVj9cjGqTfQYWeGEpcRk58WeVulISokLB Bmk2n2PX3u9+k8Y++v793mdNca/Clu4EYX0Him6cdCDDM/4SNIaL7xCx4gA4MEN53WKu n9c7o7OoEEBUtBUp+oF686EvBd1HF0Pe2n2uryKtmEk0qOlFN9zOF2xv4lLARXWT970c XqD2vlJ617n5vzNsyukvMPD3skP3jbBD2wKndk9m1kbZzScW3WRPsUqCtHBt7EI3BwA/ WLKw== X-Gm-Message-State: ABuFfogs9fwpec3S6ZcT6ccmfaUtvVBvSVyEksxPSa2n6Ov2GzFi4abM CBBl7Opn3Zv+Fg4LBTjgRVtZrA== X-Google-Smtp-Source: ACcGV61mrD9eqhs6Y3Sph53EBteAZzSIYlvW15ySh9La2vNV0aqpQtde7IbKlj9BD/8p9DYuC53IiA== X-Received: by 2002:a5d:6707:: with SMTP id o7-v6mr10890380wru.326.1538485974696; Tue, 02 Oct 2018 06:12:54 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id v10-v6sm17458681wrp.0.2018.10.02.06.12.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 06:12:53 -0700 (PDT) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya , Luc Van Oostenryck , Andrey Konovalov Subject: [PATCH v7 6/8] fs, arm64: untag user address in copy_mount_options Date: Tue, 2 Oct 2018 15:12:41 +0200 Message-Id: X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In copy_mount_options a user address is being subtracted from TASK_SIZE. If the address is lower than TASK_SIZE, the size is calculated to not allow the exact_copy_from_user() call to cross TASK_SIZE boundary. However if the address is tagged, then the size will be calculated incorrectly. Untag the address before subtracting. Signed-off-by: Andrey Konovalov --- fs/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/namespace.c b/fs/namespace.c index 99186556f8d3..51f763fb9430 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2672,7 +2672,7 @@ void *copy_mount_options(const void __user * data) * the remainder of the page. */ /* copy_from_user cannot cross TASK_SIZE ! */ - size = TASK_SIZE - (unsigned long)data; + size = TASK_SIZE - (unsigned long)untagged_addr(data); if (size > PAGE_SIZE) size = PAGE_SIZE; From patchwork Tue Oct 2 13:12:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10623637 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33C4514BD for ; Tue, 2 Oct 2018 13:13:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 276E828900 for ; Tue, 2 Oct 2018 13:13:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B0AD28908; Tue, 2 Oct 2018 13:13:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D8E9288FC for ; Tue, 2 Oct 2018 13:13:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728020AbeJBT4P (ORCPT ); Tue, 2 Oct 2018 15:56:15 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37479 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727974AbeJBT4O (ORCPT ); Tue, 2 Oct 2018 15:56:14 -0400 Received: by mail-wr1-f68.google.com with SMTP id u12-v6so2173399wrr.4 for ; Tue, 02 Oct 2018 06:12:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hNEOFJA3qECaqXrpJm2EBhk28wiALQ2kw33CEUTdhdg=; b=nNXdbbDg2VNy5SHxXbN+Ptyr1KLwmnSsBGGhJxCoeFHxmaR8fTh5dfCJuPuP2R7XcN 027ftARciHcerS2ELQQ0Z978f0Ec52kSHFCKqN2p00S/HUmL+4/+FNQ+Ee04V1jiecR8 HhckI+hYniaDUvRkL6ovrPKMPRzVpN0yqJRFIQYoJAbvkk98v1trRnIA9bACjz2T0htl sjhh3se+0ylvvlL4j4oFlIEkdCL/ALFEN07VsuQFmvaytb4hkV7XgiiEkG2pDFVbjLFm LQf987ZWYE7Z3lM2zVMpcuPdTXS7FNh6OcL7SSEDcP9l9TyEXua3IFp0e1iBvQrZGJ4M iEJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hNEOFJA3qECaqXrpJm2EBhk28wiALQ2kw33CEUTdhdg=; b=ApxVT6WQ1crhzCC/RTyIT++kA8mFGQmn0UpUyy6QqUKx+gcSwlYmA+v6ig00tryLwp mH2qnlzF0JhKQXcJ291Io3CNwUz7gKIP9ov4SocXUITDNGhQtcHqdtI21OgQ354Vtui9 VqY3nCw5JSYVNWJSKYtFyNMFOL6EruFq6moa+SsQ+yBtZfI9btaWki4RmrX4rvvLPHU6 0IZSqfVEr4sCDXmLAXHk/EFIX/AQNgojgZJ0oopx8Zy8q51Eb0wOQKIm2AsHIcjzF8eH CPeAopiW4kdnfxcDqLsryUT9oYVQbspQ2ju7U4jN/nMOOCKqHDco4e0LTj3u8CuCmFSH AAbQ== X-Gm-Message-State: ABuFfoilS66H5GJoysuFH4oOKXUh4akXW9DsFpBcn4DBYI1Fg5Xp+Uen Ap0KQw7powRMe036B2ScijeZHw== X-Google-Smtp-Source: ACcGV62jbjfhc53LoCFPGDSIPFzkIzlh2/mWrosWETT93RgqVUF8Im7cl/cWkkH9GjoPBnJtS3XIfQ== X-Received: by 2002:adf:9792:: with SMTP id s18-v6mr11253044wrb.283.1538485976256; Tue, 02 Oct 2018 06:12:56 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id v10-v6sm17458681wrp.0.2018.10.02.06.12.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 06:12:55 -0700 (PDT) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya , Luc Van Oostenryck , Andrey Konovalov Subject: [PATCH v7 7/8] arm64: update Documentation/arm64/tagged-pointers.txt Date: Tue, 2 Oct 2018 15:12:42 +0200 Message-Id: <47a464307d4df3c0cb65f88d1fe83f9a741dd74b.1538485901.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Document the changes in Documentation/arm64/tagged-pointers.txt. Signed-off-by: Andrey Konovalov --- Documentation/arm64/tagged-pointers.txt | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Documentation/arm64/tagged-pointers.txt b/Documentation/arm64/tagged-pointers.txt index a25a99e82bb1..ae877d185fdb 100644 --- a/Documentation/arm64/tagged-pointers.txt +++ b/Documentation/arm64/tagged-pointers.txt @@ -17,13 +17,21 @@ this byte for application use. Passing tagged addresses to the kernel -------------------------------------- -All interpretation of userspace memory addresses by the kernel assumes -an address tag of 0x00. +Some initial work for supporting non-zero address tags passed to the +kernel has been done. As of now, the kernel supports tags in: -This includes, but is not limited to, addresses found in: + - user fault addresses - - pointer arguments to system calls, including pointers in structures - passed to system calls, + - pointer arguments (including pointers in structures), which don't + describe virtual memory ranges, passed to system calls + +All other interpretations of userspace memory addresses by the kernel +assume an address tag of 0x00. This includes, but is not limited to, +addresses found in: + + - pointer arguments (including pointers in structures), which describe + virtual memory ranges, passed to memory system calls (mmap, mprotect, + etc.) - the stack pointer (sp), e.g. when interpreting it to deliver a signal, @@ -33,11 +41,7 @@ This includes, but is not limited to, addresses found in: Using non-zero address tags in any of these locations may result in an error code being returned, a (fatal) signal being raised, or other modes -of failure. - -For these reasons, passing non-zero address tags to the kernel via -system calls is forbidden, and using a non-zero address tag for sp is -strongly discouraged. +of failure. Using a non-zero address tag for sp is strongly discouraged. Programs maintaining a frame pointer and frame records that use non-zero address tags may suffer impaired or inaccurate debug and profiling From patchwork Tue Oct 2 13:12:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10623631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC17B14BD for ; Tue, 2 Oct 2018 13:13:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDCC528938 for ; Tue, 2 Oct 2018 13:13:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAD7C2897E; Tue, 2 Oct 2018 13:13:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E198128900 for ; Tue, 2 Oct 2018 13:13:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727786AbeJBT4S (ORCPT ); Tue, 2 Oct 2018 15:56:18 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38582 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728116AbeJBT4R (ORCPT ); Tue, 2 Oct 2018 15:56:17 -0400 Received: by mail-wm1-f67.google.com with SMTP id 193-v6so2144344wme.3 for ; Tue, 02 Oct 2018 06:12:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jKYsVlgDfkccan6ieeKzVaMnn6OiwgAPoKEMH6GgvtQ=; b=dCBVcCGfEkOp2yZaISW/VbCXrMw/roS3ig2VtB55vdMEYEdcc/N0JZvN/VK0XUG/vE q8IQc15Veee7CyQPFcN4SsbYldChP/FYEqamRzfm+EMDwScW4NnC7+nL/WVcXY4YkxXH IaLDvKPYeiZLSd6eTTyOwGRK7yY7FV+zz24fER4CRRtpt6fdP7FHKNa+sGQGNFp4xqiT 2ikGu6YSkQfB33XL8xLyxL9AM7V5tbcy1QM6XaN4QBbjg/hZJkmhb7/WqbYk+Q0i72PC 1E3XO0yS2UZtrhy8q6K5bwYxsqbd2crZpd+uOHwvRVP1OGBqcxh74WmYSqKcp9Zs8/Nq KaDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jKYsVlgDfkccan6ieeKzVaMnn6OiwgAPoKEMH6GgvtQ=; b=MwEQWAqnkMvfhhjWQyvcqaRvlPBGKqzyg70J70UvTvvtKfUykdtOiXQUVHtqj/rdp3 6F1Fcq2fMvVRvDvvu+iPvLROBvOCYmAjcpgoGrXknb9AuoWid98okzZKmMAjYdCkdxCr pFVTSAVmAxHc/x6sgPEgBXDo9YXfEDnoeZM7W7ud6bBHl1mrYIca+2dl4AwMYKD+hYiV vNs1/dOoDt5pMn85fUFB6ewzAYOn8ckG64Ih6fNmjwQqCyNOmyvh1gRMKASs9bJDpYaE qoqZpyXga7T4/aMEgBwKRCThIr/km30mfBmhekUjP/e0Kma9N4gw/8CyUpY6wc13cPMs c9KQ== X-Gm-Message-State: ABuFfohk+4to2Bq3OIrNL8fxs4nAa03uYP57mo1YwX0IxAs+QYAp8EAO ZeSEmqXt3IIK44uFnUFPXar4zg== X-Google-Smtp-Source: ACcGV61lYLeUyN6R/Xs9pciDC3H43amhfekx+exm3H5Gj+xhTN4aSmtpre7zcIkfD40I7FhghfLIPg== X-Received: by 2002:a1c:8bcc:: with SMTP id n195-v6mr1947045wmd.118.1538485977684; Tue, 02 Oct 2018 06:12:57 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id v10-v6sm17458681wrp.0.2018.10.02.06.12.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 06:12:56 -0700 (PDT) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya , Luc Van Oostenryck , Andrey Konovalov Subject: [PATCH v7 8/8] selftests, arm64: add a selftest for passing tagged pointers to kernel Date: Tue, 2 Oct 2018 15:12:43 +0200 Message-Id: <3a2c0a6b2499a328cc9471d4095ae36f0f05252d.1538485901.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a simple test, that calls the uname syscall with a tagged user pointer as an argument. Without the kernel accepting tagged user pointers the test fails with EFAULT. Signed-off-by: Andrey Konovalov --- tools/testing/selftests/arm64/.gitignore | 1 + tools/testing/selftests/arm64/Makefile | 11 +++++++++++ .../testing/selftests/arm64/run_tags_test.sh | 12 ++++++++++++ tools/testing/selftests/arm64/tags_test.c | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 tools/testing/selftests/arm64/.gitignore create mode 100644 tools/testing/selftests/arm64/Makefile create mode 100755 tools/testing/selftests/arm64/run_tags_test.sh create mode 100644 tools/testing/selftests/arm64/tags_test.c diff --git a/tools/testing/selftests/arm64/.gitignore b/tools/testing/selftests/arm64/.gitignore new file mode 100644 index 000000000000..e8fae8d61ed6 --- /dev/null +++ b/tools/testing/selftests/arm64/.gitignore @@ -0,0 +1 @@ +tags_test diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile new file mode 100644 index 000000000000..a61b2e743e99 --- /dev/null +++ b/tools/testing/selftests/arm64/Makefile @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 + +# ARCH can be overridden by the user for cross compiling +ARCH ?= $(shell uname -m 2>/dev/null || echo not) + +ifneq (,$(filter $(ARCH),aarch64 arm64)) +TEST_GEN_PROGS := tags_test +TEST_PROGS := run_tags_test.sh +endif + +include ../lib.mk diff --git a/tools/testing/selftests/arm64/run_tags_test.sh b/tools/testing/selftests/arm64/run_tags_test.sh new file mode 100755 index 000000000000..745f11379930 --- /dev/null +++ b/tools/testing/selftests/arm64/run_tags_test.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +echo "--------------------" +echo "running tags test" +echo "--------------------" +./tags_test +if [ $? -ne 0 ]; then + echo "[FAIL]" +else + echo "[PASS]" +fi diff --git a/tools/testing/selftests/arm64/tags_test.c b/tools/testing/selftests/arm64/tags_test.c new file mode 100644 index 000000000000..1452ed7d33f9 --- /dev/null +++ b/tools/testing/selftests/arm64/tags_test.c @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include + +#define SHIFT_TAG(tag) ((uint64_t)(tag) << 56) +#define SET_TAG(ptr, tag) (((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \ + SHIFT_TAG(tag)) + +int main(void) +{ + struct utsname utsname; + void *ptr = &utsname; + void *tagged_ptr = (void *)SET_TAG(ptr, 0x42); + int err = uname(tagged_ptr); + return err; +}