From patchwork Thu Nov 8 14:36:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10674355 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 90EC614E2 for ; Thu, 8 Nov 2018 14:36:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F0192879C for ; Thu, 8 Nov 2018 14:36:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 724662A548; Thu, 8 Nov 2018 14:36:25 +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 2291229C40 for ; Thu, 8 Nov 2018 14:36:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726609AbeKIAMK (ORCPT ); Thu, 8 Nov 2018 19:12:10 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38269 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726571AbeKIAMJ (ORCPT ); Thu, 8 Nov 2018 19:12:09 -0500 Received: by mail-wr1-f66.google.com with SMTP id d10-v6so21500018wrs.5 for ; Thu, 08 Nov 2018 06:36:22 -0800 (PST) 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=CyHAJ7bm8yqliTwjL59/PERrC1/EJlU4Hst47qO5nm4=; b=hTQIa3cT8mQ6PRrw+ArPxNwUIt8G3xNjt0LPrCZ2+3MjH5B+tB03HhLfo9JtaDflG7 1WS5ukgZJKhb3Ft+7oWDzcuhvWXYYqx0oGvId1rHas5NYbuZlzgh+jsCM0J8W0xqrJa0 OhmkLb2QT3xrgFMUjfPkpf38HSHLQ5o2uSKcXbsGzJDAc1p3wW4syg78MncnKzkxdlQ2 jTset9xpCPu5advaWYtuw31DIxNZhkWjXoUPz18Ntq6yzfcR8/4GKmf2sUarr6Qq88IJ IhHrM2tjOxLBZ3p5PAc6ad18rgsGMiuDoHvHKgFHyyMONd2xM9xj5Hbiv/hkt+t/CGAx Vh+Q== 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=CyHAJ7bm8yqliTwjL59/PERrC1/EJlU4Hst47qO5nm4=; b=qgiwgpn8zM8FDggrPBIRCAQVQHnQgp01af/ABVSSB67ICfCGi+9OQb5w18km0CokyP 5nMAd7Rr765sKS29qPE1f8e63I9FCd3i6DaY9zD8Aq68iqtD0Dsy6X+daWp5mxX5cEmN FADviJQc5oJGdxD1Q6csWdbgDk27WFY9duOp/cSlvAZRQIlWp9DLD4/Q3Lo92pldWGwV PNuL8iRDKJTj+U/dD1u1VCrRKxzgZ4RgbLvRdjsogGqeRwQbQwGRiRdETasNW2FwMltU eczivb7Por5O1KBuLm9VVla3ZeE5gRS8KCz1QriDqCmRbd1SA7tBttpHKMS61DyUT9AJ jnwg== X-Gm-Message-State: AGRZ1gLzVZGUrI8EHmafK7L2wmhlCwL+ffW7CR4xrAOumvUOLTamI2Pm ttJsIZQFKFZ2VtC9DngGk6IN/g== X-Google-Smtp-Source: AJdET5d0FY6pZsoxQnT5NEn9m/O0HpttSzArfI8Y3zJIn/M/EFbpljwG8ooaFhLFbogzGGQcdQFN0w== X-Received: by 2002:adf:c752:: with SMTP id b18-v6mr4088793wrh.197.1541687781406; Thu, 08 Nov 2018 06:36:21 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id k5-v6sm5421068wre.82.2018.11.08.06.36.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 06:36:20 -0800 (PST) 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 v8 1/8] arm64: add type casts to untagged_addr macro Date: Thu, 8 Nov 2018 15:36:08 +0100 Message-Id: <4a4063a3e074608b99cf22ab447fecc36d056251.1541687720.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-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 Acked-by: Catalin Marinas --- 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 07c34087bd5e..c1325271e368 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -101,7 +101,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 Thu Nov 8 14:36:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10674357 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 2888B14E2 for ; Thu, 8 Nov 2018 14:36:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 173142879C for ; Thu, 8 Nov 2018 14:36:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AC5529C40; Thu, 8 Nov 2018 14:36:27 +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 B30DC2879C for ; Thu, 8 Nov 2018 14:36:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727037AbeKIAML (ORCPT ); Thu, 8 Nov 2018 19:12:11 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50765 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726861AbeKIAML (ORCPT ); Thu, 8 Nov 2018 19:12:11 -0500 Received: by mail-wm1-f66.google.com with SMTP id 124-v6so1510991wmw.0 for ; Thu, 08 Nov 2018 06:36:23 -0800 (PST) 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=/pjzuvui9d85lC6ebp/JjM8l8T1XFTIxfHxdlRMSnSU=; b=g1wof77b/ahW159tl/OaMLW0P96a0/zVeZFYRh5g6v6wbToBXd28iFvOASCK8yKV5Y xHNqterZqD2KmkFcVcFGm+gkEQeG54Jf/H+takvz8wjdH3wdoMPjV1aR/aoFl8xbW+mR 3CDZOO7tD7iSEUdTMb+jOu+oyFpmUCbQR6pdxco9Vh1tL70iQ5jUycXJ0G3WmOgyULXv HP7R7bmaLmZ4EHXVI9J9sCIzpUalSy8bFlzRzUf2kwtLgyxlzPRWUrnL1K4XN9LUvolW Y96dsy0e/tD1Mz+ow6abkTbXTuAvzZ6CsMX4iIrftNJRgkfaRW/cIVRWqwbUc26iosdQ 6XAA== 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=/pjzuvui9d85lC6ebp/JjM8l8T1XFTIxfHxdlRMSnSU=; b=k65DoJsV+pFIBfvXnf706yAcqTPsmyYY6w5KSoJoT/lNJCyoZbN6cjf8P2zSPmJmI8 K8MAHDc63sBvBUId9kuaNQ8vdWB7ofGhe9HpjV/OiwVLh3eieRPWOsur7GE9QLdViDIh bTfgEIqAae+8f+4PpihJaYy4OvfVbzeMCdFA5mU/x7ga9wern3maM2TK5gWb4wLBptQl rgYrcpsUHq6Mnw+5mvxHe+ifqRFo5uxSUAh7NQtWF6zhNejs7CscxVwopn30RWTCXya/ C2i8+ClnI+lUZ2IB84Q15nEkzK7sdYAZ7R8XMxc8QnBZTPA+xXeUOIPlWSNec12SmNcY JsaA== X-Gm-Message-State: AGRZ1gI68FQgq8o5lntIEuVENnIRLAczFQ/dFXz0b9J3psIZ+g4QvzL1 udZqhESohzUBr8vcR/4uRaOB0w== X-Google-Smtp-Source: AJdET5fJjnrcqJrwZDIF+kL6S1eyNF+VEauTvj/4nlfwZhoIa13mwXNXonwu4vWqr6lN/+fSYDs+KQ== X-Received: by 2002:a1c:13d2:: with SMTP id 201-v6mr1411054wmt.58.1541687782962; Thu, 08 Nov 2018 06:36:22 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id k5-v6sm5421068wre.82.2018.11.08.06.36.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 06:36:22 -0800 (PST) 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 v8 2/8] uaccess: add untagged_addr definition for other arches Date: Thu, 8 Nov 2018 15:36:09 +0100 Message-Id: X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-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 Acked-by: Catalin Marinas --- 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 Thu Nov 8 14:36:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10674389 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 C1C8914E2 for ; Thu, 8 Nov 2018 14:37:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2BB826C9B for ; Thu, 8 Nov 2018 14:37:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6EF428B1F; Thu, 8 Nov 2018 14:37:01 +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 8A4FD26C9B for ; Thu, 8 Nov 2018 14:37:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726609AbeKIAMp (ORCPT ); Thu, 8 Nov 2018 19:12:45 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41773 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727027AbeKIAMN (ORCPT ); Thu, 8 Nov 2018 19:12:13 -0500 Received: by mail-wr1-f65.google.com with SMTP id v18-v6so2192611wrt.8 for ; Thu, 08 Nov 2018 06:36:25 -0800 (PST) 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=ZukT/dUNa0Ny3ny2vQGy46SLKrS4BO5zDkycm6cPI6U=; b=Gb16Vd2d0GXy5xJf7uLbCjmyiyGw/kcSiV09tZGqiQS4c5FjYJ3DtSN2p78sD5NL8J Yu3Tm1nBUr0JKb06DFlm/sg9OAiHkeadtA96DatQGcvTFe0X3Yz+4u38QKXuYLFWQO7r ZdZsPI9cYA8WnpK58iVCPR7x7p4ad7K+2zNIHukMlIO53UKw88ProRAPC5E38UFgnPMs 8hnZ2mwMMoRYlZguF9kBwPkQlLU++3vd4fcGsGzi7ZHuhrMejEt3cElmosvTCXG3RQvw z0RTxmozNtOBom8mwr04OoYOPb09mO9j0TiB1QnplSc3B0LSA5GOBmg8attUfsmiPLR9 tp+w== 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=ZukT/dUNa0Ny3ny2vQGy46SLKrS4BO5zDkycm6cPI6U=; b=kjWmUwbk1ZWgaTEP1xmuP9YChU5DN76z7a2JeiRz+EkGK01AVGGDNY8RQrpjF4RQgM jd4MybAeZrEC3I0JEEkRaQfE3aN6PMmHurW9Ft4b5BsKoKASBuBkvG5o3jCS/ItFZLi0 Pj5NUfsCuyabCsP3E+V1lgO/droUzFyDccHF1wcyTbX+VbmZoHtfGUsBxfk0imhSusTD FzXJXqeAcEuvFBRpyodlJ4P2Bes7g9KLZHI4rBVzjMgClr19vzvMpmlxiZM880FesDvO I+rSOtlAqjs4gZR1aUrPbIlFNOG2sF6ZXZhnLUQZjP8oL5+cDGIRCqM4yrfjP8+SF+/p fzng== X-Gm-Message-State: AGRZ1gIMqjzQdb/3NtraCNqBUxfMjYqHcyqcZXkrovl0toapFnUctgeR zCMGyLtkfiDMbHENAnXIC5rnjw== X-Google-Smtp-Source: AJdET5fkqa1ke/P7dlhhjrTblVnNyY5imtamk9/f/3V2XeRRGv6evK6z/uB52BsyTEJj+iulX88T8Q== X-Received: by 2002:a5d:4b05:: with SMTP id v5-v6mr4238564wrq.5.1541687784492; Thu, 08 Nov 2018 06:36:24 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id k5-v6sm5421068wre.82.2018.11.08.06.36.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 06:36:23 -0800 (PST) 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 v8 3/8] arm64: untag user addresses in access_ok and __uaccess_mask_ptr Date: Thu, 8 Nov 2018 15:36:10 +0100 Message-Id: X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-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 Reviewed-by: Catalin Marinas --- 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 c1325271e368..abc35cba134b 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -104,7 +104,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) \ @@ -236,7 +237,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) @@ -244,10 +246,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 Thu Nov 8 14:36:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10674365 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 6A5C817D4 for ; Thu, 8 Nov 2018 14:36:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5929C26C9B for ; Thu, 8 Nov 2018 14:36:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49BD02879C; Thu, 8 Nov 2018 14:36:31 +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 DD5102879C for ; Thu, 8 Nov 2018 14:36:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726571AbeKIAMQ (ORCPT ); Thu, 8 Nov 2018 19:12:16 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50774 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727082AbeKIAMO (ORCPT ); Thu, 8 Nov 2018 19:12:14 -0500 Received: by mail-wm1-f67.google.com with SMTP id 124-v6so1511198wmw.0 for ; Thu, 08 Nov 2018 06:36:27 -0800 (PST) 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=XFiY84rm4WtGUkeGnRX1ezxk6XhL8yE5HslON+43E5A=; b=oI+aXnMV67bGaMcJR9iVpv8//10td45km8L6aUAt2U7BKqk1YcqEFnL2kiwXI60GJo SZ/CWqH8TK1BouvBvRRzyXbwgS+WPi1NX50zFJ4aZOaLhWwHownP5SyGqmZyTvxteJal x0mda4AQkeS6YISyxX7xYqbJJdlvjtQRCohgvGk8JBce2yGqrCNVYfUUXDV/xs8CBuM0 1kAPsLjjZHDD9GoxuZyOgQVVPU9Vq8pVh34mVeWeNrhpoiskyIgvnUHpn6CnYXhNB8Gf fc13RpNIM2IDnaeH5D7Twtt/fOx+AjFtdmrj8a5LSxCAkD4uliwAac75+fL+PZR7qTT3 3SOA== 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=XFiY84rm4WtGUkeGnRX1ezxk6XhL8yE5HslON+43E5A=; b=pzPhLCC+q+4RHSY+5cV3dYSuygUsVPGhntrOfBL/4ECJvgq+8pxH80aR7LLh4y4bC+ 5PApneZEbSAclY07PWctfN+WiiuYUlyOneftddANZqlj0gJCII/1WvN7l7//T0zdC1Y1 AbQ7TjXFszFj23FVFf26JI28hEsyZK1AE6V2laJ3yVIo8T+WMeWBxIv6OTrD7i1Lvhmf pdThHITAZSGOF8NUSyanZ57Uom7gRicCIIzlIslkEtgcE0aZWnUuyURD4zAMfHhuXMuF pXMNhUOY+Iz1ptPq1EC3oR5bpUV7CYNk8r+NXdRWJNummIq+vbaoKLdZ/vTbcTKktsES 6OTA== X-Gm-Message-State: AGRZ1gLnaC2h7cvo+sPzuOEYor0sKKBgZsXuNQMFhW63pxB+HFeiGwls dutM+7ZQuIX5yAtzVWAVxgLI3Q== X-Google-Smtp-Source: AJdET5fLJZXRAYzbTbJsD9GsxFNMuZQD5qXtXF3tsrt1pqTH3zYu3HOOugbRpVAPkx1jngHW7yqCPg== X-Received: by 2002:a1c:e40b:: with SMTP id b11-v6mr1500427wmh.100.1541687786099; Thu, 08 Nov 2018 06:36:26 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id k5-v6sm5421068wre.82.2018.11.08.06.36.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 06:36:25 -0800 (PST) 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 v8 4/8] mm, arm64: untag user addresses in mm/gup.c Date: Thu, 8 Nov 2018 15:36:11 +0100 Message-Id: X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-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 f76e77a2d34b..6ff310818616 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -677,6 +677,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)); /* @@ -840,6 +842,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 Thu Nov 8 14:36:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10674363 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 364D314E2 for ; Thu, 8 Nov 2018 14:36:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24DFF26C9B for ; Thu, 8 Nov 2018 14:36:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17B7A2A34F; Thu, 8 Nov 2018 14:36:31 +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 BB89B26C9B for ; Thu, 8 Nov 2018 14:36:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727128AbeKIAMP (ORCPT ); Thu, 8 Nov 2018 19:12:15 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34550 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726862AbeKIAMP (ORCPT ); Thu, 8 Nov 2018 19:12:15 -0500 Received: by mail-wm1-f66.google.com with SMTP id f1-v6so1690322wmg.1 for ; Thu, 08 Nov 2018 06:36:28 -0800 (PST) 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=pCI3XzgNVAltAQe0ygEc6WjcTSNZu+vDSueRg2rkboA=; b=UP+XhJbt7rG/bdEpw8fc31VRF5aLTB6BTp86/sKBPDdvzf+3rKxrZx+R4xkXmuYNk4 Z2kSoGRZtY2xgb0cZLZ8nqWLECPTlNaPdP21J5ZftO9/AJWV27UNRA3MqMVTh/5VBt86 OR25TGd6GfMgbPUcVLtTp1LdrRAy+ildKK5CGWBA4J0gfpCpY2qo+ocTQb4EWphPlU6Q auFXwXntmIyQWzfLokABGdc0KwvDYW58Q+kRcY3/53A5RFB2TyvvkOfcZPB/L/44UZEC 8kDE/Ckdr3nMddglr5ecwDqcjOXtIhIheYGjYA9pJ/KdMyecy+Hsgg9Tkw2BDFQ1m7aq kRKA== 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=pCI3XzgNVAltAQe0ygEc6WjcTSNZu+vDSueRg2rkboA=; b=aaZ5+J8wt6zzAj8ocTIev8UOvD37OncOkf6SP98Jr2L7NindKT4uNHv1tbGc0lMrcH KSq1uv1VGy2CxRhBiEMbQDOE6pl9ItdzOncZh20dgNaZ5UZYqAE9yR3N2MS0+DAeh+1J T+PulOC0rd46rNuTcRVC5+0Z2TvOmEhrw6TQaSbF/c4U0gVPzyuMKs6mcfxoPBG4XKhR LyDniW/FhLZTkPj3+a9th961qqfpguHz4yU43DC8/GDMG5hooFZ7lz2wfaTjCpxPqgPk KLvlFWF0j118SU8Qa1DsgPODnwA7JEaq37ct+69IjXrFNZe+dqeKeZXXeUX5fgRgaRHj piWg== X-Gm-Message-State: AGRZ1gK7NgSd72rh4R4PRQNiI2elMCtWV/B8aQ79i8cM27ZdMinMEEVP br45+w77twLCkQBIJ4ph1n8AUg== X-Google-Smtp-Source: AJdET5c+OpdgjUiZO9kVFnzi+iLq8I4Ia27Tsi9lTwsCI5F43MyC9kiQR9b4hA1qM6mueQyUfoxirQ== X-Received: by 2002:a1c:154a:: with SMTP id 71-v6mr1368940wmv.83.1541687787548; Thu, 08 Nov 2018 06:36:27 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id k5-v6sm5421068wre.82.2018.11.08.06.36.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 06:36:26 -0800 (PST) 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 v8 5/8] lib, arm64: untag addrs passed to strncpy_from_user and strnlen_user Date: Thu, 8 Nov 2018 15:36:12 +0100 Message-Id: <4969eac81732e555ca1ec102c12eb1e29c82ed29.1541687720.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-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 Thu Nov 8 14:36:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10674385 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 92A4714E2 for ; Thu, 8 Nov 2018 14:36:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8078E28B1F for ; Thu, 8 Nov 2018 14:36:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 719E32B0BB; Thu, 8 Nov 2018 14:36:53 +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 1F82D28B1F for ; Thu, 8 Nov 2018 14:36:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726801AbeKIAMi (ORCPT ); Thu, 8 Nov 2018 19:12:38 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37595 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727105AbeKIAMR (ORCPT ); Thu, 8 Nov 2018 19:12:17 -0500 Received: by mail-wr1-f68.google.com with SMTP id o15-v6so17865734wrv.4 for ; Thu, 08 Nov 2018 06:36:29 -0800 (PST) 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=yMfnGtGqvRCyrqlswY+Q1yEYdnjSJs7L5yVY6s2C8lo=; b=OSTpJoAOkRI0ha5rclaP8H3RmP+9ftj4eIBMetkNB1rSZYKkx6QyMUtvsfT1I3Kbsi nqq49Yy9O0XIeGCBlu0DPUC39BhChXKHgATeWUk2Fi3gh0t1QL8BYV6K4jiy3T2i6GNH VRkY3HLu0OXnhKnVS6lf3PrTZZrby7lQuqhxR85J0t5SJLDHDokRqms7hvRLEo0fiOk5 qXqzsjE//9TlVAWpqziY4CaFF5r83iPytuR7OvbTtP/y28wAZdWtDZB4Xu6aS0GvYmpk /IynZxRnIUJET/vhUgCb7aqU51FOWJpPnAr9pJIHVMZ/tONQTR1EhR7OVdPJRK9CIslK 04FQ== 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=yMfnGtGqvRCyrqlswY+Q1yEYdnjSJs7L5yVY6s2C8lo=; b=G0m5oYr58BaHLa1jRlsRERY0YecchRp4YtYVASHITes4kSFok1X/VwgUKtI+NxqAUL HeIYSPjDKpKFqMEEDMcJ27NW9NcIMlHVCwVUvPSKq0qnbpaQG+ck8PxXguH9J+0YbchO phqEcrgRW/KmrJm3ro0ilRDOUrXstcjA8PbFdM7hcm7Cw5zJoQv+ZPwK6lmVOWOq5B/H O/jaFSGnJaI60E/2oaxez1KFZbSR0youeBOaeAup+74y6EE6Csl9Ucr/EoQ4mGXzAxyJ OjqgBd9B7r47e3Ej7XwEbx0R5FiJN2EuA++xcffyp2DvGNZvg529sgUYwFQHX/a+H3sx KUHw== X-Gm-Message-State: AGRZ1gL+7GI9E2GFrHxVesx/dxu4Wk2EX5KfPGDy/6z3FtesiCAC8MWn /pP4rNBbwFnzBFaEUyjDjg+9eg== X-Google-Smtp-Source: AJdET5eI6mep1KozRP67zq2F57bYi00Ufy/TNGQH9gCb351dH5ClKuaGSs0MjfRiBrsX95XmOTVJkQ== X-Received: by 2002:adf:f382:: with SMTP id m2-v6mr4327147wro.111.1541687789216; Thu, 08 Nov 2018 06:36:29 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id k5-v6sm5421068wre.82.2018.11.08.06.36.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 06:36:28 -0800 (PST) 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 v8 6/8] fs, arm64: untag user address in copy_mount_options Date: Thu, 8 Nov 2018 15:36:13 +0100 Message-Id: <12fc6c9e4896b394800776c54b16b26e2003a9df.1541687720.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-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 98d27da43304..1f1f998d15ed 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2674,7 +2674,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 Thu Nov 8 14:36:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10674369 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 3E87614E2 for ; Thu, 8 Nov 2018 14:36:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D70526C9B for ; Thu, 8 Nov 2018 14:36:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DF6229C40; Thu, 8 Nov 2018 14:36:35 +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 AABCD26C9B for ; Thu, 8 Nov 2018 14:36:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727326AbeKIAMT (ORCPT ); Thu, 8 Nov 2018 19:12:19 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46531 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727246AbeKIAMS (ORCPT ); Thu, 8 Nov 2018 19:12:18 -0500 Received: by mail-wr1-f67.google.com with SMTP id 74-v6so21475256wrb.13 for ; Thu, 08 Nov 2018 06:36:31 -0800 (PST) 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=AfT6+8vP45oXrV17rGSZ9pzYS0my+RLSPjgVa2gqAd4=; b=UXht8r8Y+LVp07kCtfXSBeRBhpCaVOvYm1P+l9gMKK/QSvkAY4eFI/F/7dNdhFa+6s 03WsHwOPySnNl0C8RLlGZrgGNvf5upI9wpT2QD8fZu8QPcUo14dOOKGhsT3Vt3N2Xsfz jNCbI1daeAMYzEOF5k+/52Kcgvpjbbd1ZJorRlAFSppDB08ydUZoSHLoh0bXliV119yC tyWxnr6yN/1x8ngIwCnTTq6z3enqkxHT7u0Gob0KyEf1crq1MQb3JzblYwR/nihHzcHC ZK14++eId0uzOYOuwdG4frYt1cxu7q2wA7WvAPLwPwotre1YMk4rWNPG7CM0tgU1zuH6 v3bg== 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=AfT6+8vP45oXrV17rGSZ9pzYS0my+RLSPjgVa2gqAd4=; b=WfrOyBhVufrdLoAoJqXcJaAGtTy+vWdYG+81eXr7lH8tZOO9Bt/Gg2bI/ZAUEXZOqK uYSec5ZJuCitRMtZG+h6yZcBIiKZ/RFs3HRXyZqijylqD5lacT9t75Iyjjx7gSELCiGd wq/yGh/WDPE8SOdtnSu7NT+ahpggHJfyETJMkj9Bpt++QKw+tbb/VmOFlFYqc9GQiiXt 3SJSpKTaLQ1xqNZHM1ltEbr5v2ENondpj+WbZmz7U3xAMsyvHtidgbdqmPRh85iR2/bu BmD8Rr776GltfZ3xgqUIzGoSb1fOkpQHEvoW2ajyCGgNs3jpbYYqCg3c6V1vtQkGuyBf FYTQ== X-Gm-Message-State: AGRZ1gKlVG2goXAPVD5mitUc0Aia60aROr1bfReH+UCP+svOf/mqRnVD IVuvZAdK2zvywhK4oyWCHci7tw== X-Google-Smtp-Source: AJdET5cd+Vxy+CiHtQ9mm6FtFF35wdB6lNLfr2BV8z1ME65fDt3kZ6JEKazzaGEHLM0pA02L2pbaZA== X-Received: by 2002:a05:6000:1182:: with SMTP id g2mr4510493wrx.310.1541687790933; Thu, 08 Nov 2018 06:36:30 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id k5-v6sm5421068wre.82.2018.11.08.06.36.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 06:36:30 -0800 (PST) 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 v8 7/8] arm64: update Documentation/arm64/tagged-pointers.txt Date: Thu, 8 Nov 2018 15:36:14 +0100 Message-Id: <8526edb07fd5a762847306bba89fbadbb19210b7.1541687720.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-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 | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Documentation/arm64/tagged-pointers.txt b/Documentation/arm64/tagged-pointers.txt index a25a99e82bb1..f4cf1f5cf362 100644 --- a/Documentation/arm64/tagged-pointers.txt +++ b/Documentation/arm64/tagged-pointers.txt @@ -17,13 +17,22 @@ 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. +The kernel supports tags in pointer arguments (including pointers in +structures) for a limited set of syscalls, the exceptions are: -This includes, but is not limited to, addresses found in: + - memory syscalls: brk, madvise, mbind, mincore, mlock, mlock2, move_pages, + mprotect, mremap, msync, munlock, munmap, pkey_mprotect, process_vm_readv, + process_vm_writev, remap_file_pages; - - pointer arguments to system calls, including pointers in structures - passed to system calls, + - ioctls that accept user pointers that describe virtual memory ranges; + + - TCP_ZEROCOPY_RECEIVE setsockopt. + +The kernel supports tags in user fault addresses. However the fault_address +field in the sigcontext struct will contain an untagged address. + +All other interpretations of userspace memory addresses by the kernel +assume an address tag of 0x00, in particular: - the stack pointer (sp), e.g. when interpreting it to deliver a signal, @@ -33,11 +42,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 Thu Nov 8 14:36:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10674371 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 9FC2914E2 for ; Thu, 8 Nov 2018 14:36:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EB5726C9B for ; Thu, 8 Nov 2018 14:36:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8264A2A34F; Thu, 8 Nov 2018 14:36: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=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 0090F26C9B for ; Thu, 8 Nov 2018 14:36:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727362AbeKIAMV (ORCPT ); Thu, 8 Nov 2018 19:12:21 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52712 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727316AbeKIAMU (ORCPT ); Thu, 8 Nov 2018 19:12:20 -0500 Received: by mail-wm1-f68.google.com with SMTP id r11-v6so1495565wmb.2 for ; Thu, 08 Nov 2018 06:36:33 -0800 (PST) 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=rTcNvHgzBcnv8yHP5cVBE2DYrsiz3ttqK4qPmsK+xBo=; b=mP7BwUREcnEcGSgnJc1TDgXr13K42B6BP4F15hPXDeIHuQX2uOp8Snkbsq/rDAlE8d GSxzbR40FboXXdUWHFzDhkyUPKNmYpTbYubEcgFD0CeD80LjOR+XkyuSoGS0VJJv/LH/ U6bwKzwuc24ye0v6iPDL7C1rJ5l8CkubR7mup/yvtsiMkdMISH/cH5hOvczkzzBlrJ0p 6t1bLiFLEwT4ih2n9wtnExO7TRHpeETynQbzZK9MPILt2vlGyetQLGs6FdHqDdSjfj09 3QppCswB2VwG1hTqjfpGg82D4sfV1zFc5WOav3Zmp21ggvvVuSxtI+UVd6rkaY7vKPH0 +Gog== 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=rTcNvHgzBcnv8yHP5cVBE2DYrsiz3ttqK4qPmsK+xBo=; b=LqdZQx2KlFQWIn6fHgj6A+aS0v1KhmBF4fjAX1svEcoabONT/7mlyiMoQBoMpmPDvV pOOoDrze/yJMBqm0OXuxJ+UGzELokTILrbPHrvOJLf49hGMG6kCikht2x/PpZkbfvjPe 5Qsewj/gDY1WReOSGygy7NFFL/6g15pSfy/188IWkotoxnygAHKiEmp/nG+UYAXpjtsS EfD5ut4h933LH2h9DC4Fi/XLVPr7z90oAmTWitOxKgrMZhTH6d0GOuEqWCUFO8rLKhhj 3Qs0f8yapDxe0GgENgnO0zgOoCw7FdpOZON/wkwh89Yf4nePdn2fU0t1qCsdGSd/Msax /CIg== X-Gm-Message-State: AGRZ1gIgpBUhSX/fKLzRj51iiUIfG0a7GkkNiVU69GoDOL44KF8sHcX1 GzvC3EXd32c+duZwELBbfCLXZA== X-Google-Smtp-Source: AJdET5etM7uj3EUTtVycpWGYsbTyj7fUXc6thqPRDiCt2FdD9fuqZ1p8f/aw/QlkU3PTYPTHJhfbWQ== X-Received: by 2002:a7b:c0cc:: with SMTP id s12-v6mr1514540wmh.39.1541687792444; Thu, 08 Nov 2018 06:36:32 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id k5-v6sm5421068wre.82.2018.11.08.06.36.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 06:36:31 -0800 (PST) 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 v8 8/8] selftests, arm64: add a selftest for passing tagged pointers to kernel Date: Thu, 8 Nov 2018 15:36:15 +0100 Message-Id: <08e86fb73c3f0aeb60888939e34b0c0fa69063b5.1541687720.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-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; +}