From patchwork Tue May 28 17:05:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 10965539 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 60973112C for ; Tue, 28 May 2019 17:05:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49B40285FD for ; Tue, 28 May 2019 17:05:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A00128673; Tue, 28 May 2019 17:05:06 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 C4816285FD for ; Tue, 28 May 2019 17:05:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726619AbfE1RFF (ORCPT ); Tue, 28 May 2019 13:05:05 -0400 Received: from mail-eopbgr760129.outbound.protection.outlook.com ([40.107.76.129]:47302 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726600AbfE1RFF (ORCPT ); Tue, 28 May 2019 13:05:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavesemi.onmicrosoft.com; s=selector1-wavesemi-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TFFrmbFA9nqARmnrdqQo+9mxZQUWcKK4+0AIgxNUaxE=; b=FapHvhLUQqCXUqzXk4qDKYZUoRiv69wxINPAzszS917WwzMLJbthwDOsnUHT8IAfBd1bjYu8Lnq3fqanhnTjzhIhBtcZYTSZjUnO9XCF37zPBxQ7Jr/b8F4fdCv80EkfUFj0UQ4wVilvR5D3UCIxoiPdzWN9/rcMTNqAKY/vRaI= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.174.162.17) by MWHPR2201MB1152.namprd22.prod.outlook.com (10.174.167.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1922.15; Tue, 28 May 2019 17:05:03 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::90ff:8d19:8459:834b]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::90ff:8d19:8459:834b%7]) with mapi id 15.20.1922.021; Tue, 28 May 2019 17:05:03 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Paul Burton , Julien Cristau , Yunqiang Su , "stable@vger.kernel.org" Subject: [PATCH 1/2] MIPS: Bounds check virt_addr_valid Thread-Topic: [PATCH 1/2] MIPS: Bounds check virt_addr_valid Thread-Index: AQHVFXd9GkRqXxEIYUuNu8zTlmfmBg== Date: Tue, 28 May 2019 17:05:03 +0000 Message-ID: <20190528170444.1557-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR07CA0060.namprd07.prod.outlook.com (2603:10b6:a03:60::37) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:24::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 373e4062-a519-4915-2a27-08d6e38ea009 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600148)(711020)(4605104)(1401327)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:MWHPR2201MB1152; x-ms-traffictypediagnostic: MWHPR2201MB1152: x-ms-exchange-purlcount: 1 x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1303; x-forefront-prvs: 00514A2FE6 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(346002)(376002)(39840400004)(136003)(366004)(189003)(199004)(68736007)(73956011)(2616005)(476003)(99286004)(186003)(316002)(64756008)(66446008)(66556008)(54906003)(66476007)(966005)(256004)(102836004)(478600001)(2906002)(42882007)(6506007)(14454004)(52116002)(386003)(6116002)(3846002)(81156014)(6486002)(2351001)(6916009)(81166006)(8676002)(6436002)(36756003)(5660300002)(5640700003)(50226002)(53936002)(26005)(2501003)(8936002)(25786009)(4326008)(71190400001)(71200400001)(6306002)(6512007)(66946007)(486006)(44832011)(66066001)(305945005)(1076003)(7736002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1152;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: LYOAGnXXNyJJ2YwU4KkRmvZ8NY37pN2KzXvMRNPw1f7QnHNEHkOyX0EbKf9V1q/mTYrnBpaNt7x+UcFsy9soH5MdvqTPS+zjmmKngotPNM9pqscjw4M3rN+4tfCIE2HM27hDYjImamy9OAHRw+RiuhWYLJ2KHw4S6XpNGhs2wk0j/MAje7yhWaTLZK3kFLlFrg9dzqrUoq4Odm5gN/RNDPUeMEOBrS7nvaIVSRYdry3TwjAKnUVhdK/PMwc4MDwxFzl9uqyRIZJPZmq45Z7I7Jt7Tzyod39NH6Okx8P5Db0lTQA0qt9oYejzPKt42hlI99ehFe/0YNe4UAnWo0h0Kxd4Iq7pdHi3kabRX3ANjDtdg6pj8GMM375NzERFbZRuaf59EQQCoSy2mn+qBaVYe+BBrhTz4Oj+zQ406rxPOUg= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: 373e4062-a519-4915-2a27-08d6e38ea009 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 May 2019 17:05:03.4334 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: pburton@wavecomp.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1152 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The virt_addr_valid() function is meant to return true iff virt_to_page() will return a valid struct page reference. This is true iff the address provided is found within the unmapped address range between PAGE_OFFSET & MAP_BASE, but we don't currently check for that condition. Instead we simply mask the address to obtain what will be a physical address if the virtual address is indeed in the desired range, shift it to form a PFN & then call pfn_valid(). This can incorrectly return true if called with a virtual address which, after masking, happens to form a physical address corresponding to a valid PFN. For example we may vmalloc an address in the kernel mapped region starting a MAP_BASE & obtain the virtual address: addr = 0xc000000000002000 When masked by virt_to_phys(), which uses __pa() & in turn CPHYSADDR(), we obtain the following (bogus) physical address: addr = 0x2000 In a common system with PHYS_OFFSET=0 this will correspond to a valid struct page which should really be accessed by virtual address PAGE_OFFSET+0x2000, causing virt_addr_valid() to incorrectly return 1 indicating that the original address corresponds to a struct page. This is equivalent to the ARM64 change made in commit ca219452c6b8 ("arm64: Correctly bounds check virt_addr_valid"). This fixes fallout when hardened usercopy is enabled caused by the related commit 517e1fbeb65f ("mm/usercopy: Drop extra is_vmalloc_or_module() check") which removed a check for the vmalloc range that was present from the introduction of the hardened usercopy feature. Signed-off-by: Paul Burton References: ca219452c6b8 ("arm64: Correctly bounds check virt_addr_valid") References: 517e1fbeb65f ("mm/usercopy: Drop extra is_vmalloc_or_module() check") Reported-by: Julien Cristau Tested-by: YunQiang Su URL: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=929366 Cc: stable@vger.kernel.org # v4.12+ Reviewed-by: Philippe Mathieu-Daudé --- arch/mips/mm/mmap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c index 2f616ebeb7e0..7755a1fad05a 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -203,6 +203,11 @@ unsigned long arch_randomize_brk(struct mm_struct *mm) int __virt_addr_valid(const volatile void *kaddr) { + unsigned long vaddr = (unsigned long)vaddr; + + if ((vaddr < PAGE_OFFSET) || (vaddr >= MAP_BASE)) + return 0; + return pfn_valid(PFN_DOWN(virt_to_phys(kaddr))); } EXPORT_SYMBOL_GPL(__virt_addr_valid); From patchwork Tue May 28 17:05:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 10965541 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 F081C112C for ; Tue, 28 May 2019 17:05:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAC41285FD for ; Tue, 28 May 2019 17:05:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF25628673; Tue, 28 May 2019 17:05:07 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 70BB2285FD for ; Tue, 28 May 2019 17:05:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726736AbfE1RFH (ORCPT ); Tue, 28 May 2019 13:05:07 -0400 Received: from mail-eopbgr740138.outbound.protection.outlook.com ([40.107.74.138]:6077 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726600AbfE1RFG (ORCPT ); Tue, 28 May 2019 13:05:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavesemi.onmicrosoft.com; s=selector1-wavesemi-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P8y8zpvR8eIaKBVFI/gn8od5yvKJPTrHdwCTyw9QYw4=; b=MZd312xuDnEQoXWldvCRHyWQQBulMNj3gr+yNIQFUcwG5f6u18bpBhsOq+derL9f6KhX1irc/zSQDJZ8MDsACI+cfoNBF4NYX/frXcb55het/yiH1aKMI1B9TvaRfg3h7ArJMQZWrCj/WCORYwUgwqJ+McNJS84AR3FxcQ4cNH8= Received: from MWHPR2201MB1277.namprd22.prod.outlook.com (10.174.162.17) by MWHPR2201MB1725.namprd22.prod.outlook.com (10.164.206.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1922.15; Tue, 28 May 2019 17:05:04 +0000 Received: from MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::90ff:8d19:8459:834b]) by MWHPR2201MB1277.namprd22.prod.outlook.com ([fe80::90ff:8d19:8459:834b%7]) with mapi id 15.20.1922.021; Tue, 28 May 2019 17:05:04 +0000 From: Paul Burton To: "linux-mips@vger.kernel.org" CC: Paul Burton Subject: [PATCH 2/2] MIPS: Make virt_addr_valid() return bool Thread-Topic: [PATCH 2/2] MIPS: Make virt_addr_valid() return bool Thread-Index: AQHVFXd+OhmrHtHwAUuhxD1EVo2LSw== Date: Tue, 28 May 2019 17:05:04 +0000 Message-ID: <20190528170444.1557-2-paul.burton@mips.com> References: <20190528170444.1557-1-paul.burton@mips.com> In-Reply-To: <20190528170444.1557-1-paul.burton@mips.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR07CA0060.namprd07.prod.outlook.com (2603:10b6:a03:60::37) To MWHPR2201MB1277.namprd22.prod.outlook.com (2603:10b6:301:24::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [12.94.197.246] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: cd6ccf3a-b6e2-4e45-b7d9-08d6e38ea098 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:MWHPR2201MB1725; x-ms-traffictypediagnostic: MWHPR2201MB1725: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:883; x-forefront-prvs: 00514A2FE6 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39840400004)(366004)(376002)(136003)(346002)(189003)(199004)(5640700003)(25786009)(2906002)(316002)(478600001)(71190400001)(71200400001)(476003)(2616005)(53936002)(446003)(186003)(486006)(11346002)(6916009)(14454004)(68736007)(305945005)(42882007)(2501003)(6436002)(6486002)(44832011)(26005)(4326008)(8676002)(3846002)(6116002)(107886003)(81156014)(81166006)(2351001)(5660300002)(52116002)(76176011)(1076003)(102836004)(7736002)(6512007)(6506007)(386003)(64756008)(99286004)(73956011)(66946007)(50226002)(66066001)(66476007)(66556008)(36756003)(66446008)(256004)(8936002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR2201MB1725;H:MWHPR2201MB1277.namprd22.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: FUw8NIpY/ozVtYQ96VN/6k2IV4n5QpJA7LcyM9MyeRrZVk0//ihCnUmSgszNYYPMasoQuBHtSt2L1WUP5iZD7ILGN+Bd94EBbKCip1VYztO7WETIUoiXtBQYvDz4cLY22GGJbXi3ioQfGwyLYzFNhjZ1Fh2giiPJbsWzkJVY5G/ba+YJGneL1Gf7XS6Py7eoQ66Z1YnG8awDpxw0uYyTQOSxT3yBpc7sdvIUyZJL4tZbVVQZAKyO6g1z6ies338dDjNV+0UV3YpGrPvGaR0GkwAX4oaVWzF1nMePRDG1Qkkz+HFYkxR3o6dT4ofR5A8HIV+nXbw32t7VG1Of5TRZ5dJzMmUaUpxp6XYjK//0QpkPRRJZvmu4gobhIdmxPf15R7DRcTWDeHRS09+LvT9nWfk6RQ3eDyFpp93iQxuWGHA= MIME-Version: 1.0 X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd6ccf3a-b6e2-4e45-b7d9-08d6e38ea098 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 May 2019 17:05:04.5483 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: pburton@wavecomp.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1725 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP virt_addr_valid() really returns a boolean value, but currently uses an integer to represent it. Switch to the bool type to make it clearer that we really are returning a true or false value. Signed-off-by: Paul Burton Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé --- arch/mips/include/asm/page.h | 2 +- arch/mips/mm/mmap.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h index 6b31c93b5eaa..a25643d258cb 100644 --- a/arch/mips/include/asm/page.h +++ b/arch/mips/include/asm/page.h @@ -249,7 +249,7 @@ static inline int pfn_valid(unsigned long pfn) #define virt_to_pfn(kaddr) PFN_DOWN(virt_to_phys((void *)(kaddr))) #define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr)) -extern int __virt_addr_valid(const volatile void *kaddr); +extern bool __virt_addr_valid(const volatile void *kaddr); #define virt_addr_valid(kaddr) \ __virt_addr_valid((const volatile void *) (kaddr)) diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c index 7755a1fad05a..50ee7213b432 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -201,12 +201,12 @@ unsigned long arch_randomize_brk(struct mm_struct *mm) return ret; } -int __virt_addr_valid(const volatile void *kaddr) +bool __virt_addr_valid(const volatile void *kaddr) { unsigned long vaddr = (unsigned long)vaddr; if ((vaddr < PAGE_OFFSET) || (vaddr >= MAP_BASE)) - return 0; + return false; return pfn_valid(PFN_DOWN(virt_to_phys(kaddr))); }