From patchwork Tue Apr 20 16:50:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 12214697 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,PDS_BAD_THREAD_QP_64,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7DD7C433B4 for ; Tue, 20 Apr 2021 16:50:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6949F613D4 for ; Tue, 20 Apr 2021 16:50:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233435AbhDTQvS (ORCPT ); Tue, 20 Apr 2021 12:51:18 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33302 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233425AbhDTQvR (ORCPT ); Tue, 20 Apr 2021 12:51:17 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13KGaobr173668; Tue, 20 Apr 2021 16:50:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=dzcqGSkZyw/D6a1e/bPszDOHvl2ObGE0tmn5ByRCFR0=; b=znHSlSPDmDRO0AjA+5IPFrMG4kvaA6/i9dubPJzRxkeZ8lGpOg+wme2IvoqMXyKZeadw 6pDD/G3uys2pvl3B0yL3pf728qlbHRrMb1g5NtVKrCx874OVXUb6KQJzrptPwLSHAYR+ f16o6ObbgETD8wQvOU4YBunUk5HJK3z99xBu7eo6O4A5hi2H/Lz7tLtWucWEnO9XkH4+ 8N6w8bmU+qSzcjQugYlEOZTDbN9YmEb4EeYbPd50C3qZNU4yakCucPeTDbAI+qun5Xgu HX9Fg3jTwqUtGgFtODtBUUgtbbm3v7kqS2QAJDihHsr2qSNb/1lrfjtkaHafZ1hv/tc5 Lg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 38022xy8qj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Apr 2021 16:50:16 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13KGZtsO102703; Tue, 20 Apr 2021 16:50:15 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by userp3020.oracle.com with ESMTP id 3809esxw95-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Apr 2021 16:50:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FbC7rsIXwEZxiWhgjdTlfNrOrYarqKvL8Oy6UkCKeO5T45ETZge0Cy+13cobVrUWR2cCm9TKUg7GCqzz8AH0Jxby2L56FrO9/a75J//elDRcobd8bIPpqFjXQeMbGKwIU8gLISaxfwfFwFAFsWTNTcrO6pkKzVYwClZIUwtd7Uwoz7zWw7vcQhVVJV7ELsIkbI/TXMPO/B/gWoSh3blUqsUnmD3KgEp3hbSGayT97arNnLwvo9Mt9t8vOPF0qKjXCSkEnL7un6Bi0DAzjlRfOZSZ4P3d9siQOuFcmapqu9ta+BW/GIpycoy3yjJcFZsP1BcBSUKq0HgWx0VWpmwmrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dzcqGSkZyw/D6a1e/bPszDOHvl2ObGE0tmn5ByRCFR0=; b=DHhzsGNQkRgZSAYFMZ3RVB/QbtzAmnneANCTvjzcdcSOZYhC+dvdCLvd1Y3Fc1Lh7EAnhBMCU5ttkqrpi+F6zDlP7gP1vdq76UuwmRotHwyJEMHPtb8iJsCbwarZoAblChKxFilsnwstiiYawuOEib74AcmS/UkLkCifOsBovwxkosmNZoh9D3w1jEOjl5gVGY17ctFK5Zt42W9dVFkc576T2EbzEz522eufJHN8HvlakzlPMa4qRTg6Pr3CavmGPWbI/f+5XCkg6QX/UrYmHzvlGZRQif5wH2TKM8OohST7+jtyDcjAKl6a3qxLUQmd0r9tNHoJiINVdi4NmCCLwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dzcqGSkZyw/D6a1e/bPszDOHvl2ObGE0tmn5ByRCFR0=; b=qBc1+owSFuEopiS0zuUXItO1bCCp5AvSHlk9P6eDF5z3rXjpA+iFR29YSfkIRdCfnlmVhxC18ts0Cxal0yhoa51rjJ6tVKkoWscbK69yas3DNQf1BKOJK9QwwmtXXZdyvJ5VWYpq5NXFlVziUOQqTZdUpW4OyXP+D7Oai9RSAmI= Received: from MWHPR10MB1582.namprd10.prod.outlook.com (2603:10b6:300:22::8) by CO1PR10MB4772.namprd10.prod.outlook.com (2603:10b6:303:94::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Tue, 20 Apr 2021 16:50:13 +0000 Received: from MWHPR10MB1582.namprd10.prod.outlook.com ([fe80::353a:1802:6e91:1811]) by MWHPR10MB1582.namprd10.prod.outlook.com ([fe80::353a:1802:6e91:1811%8]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 16:50:13 +0000 From: Liam Howlett To: Catalin Marinas , Will Deacon , Julien Grall CC: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Liam Howlett , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH 1/3] arm64: armv8_deprecated: Fix swp_handler() signal generation Thread-Topic: [PATCH 1/3] arm64: armv8_deprecated: Fix swp_handler() signal generation Thread-Index: AQHXNgU7pAWIynV4NUyh79ZCugEeMA== Date: Tue, 20 Apr 2021 16:50:12 +0000 Message-ID: <20210420165001.3790670-1-Liam.Howlett@Oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.30.2 authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=oracle.com; x-originating-ip: [23.233.25.87] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 667a504d-3ed2-4e5f-7c57-08d9041c5ddf x-ms-traffictypediagnostic: CO1PR10MB4772: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: qfAoNk2aQchsMUGi/RhIfy9VOoAt853OrOrKK6PCeMskcU1/tW7kgEhpO5HcJyIz25Yh8cUYp0MuqfCTtpLrSrSTbdnD9A+PncQ441A33UNcNuv2x9CTKauBqmPumf2mhTamN9SbN589HgVJLjL3bETu/u+tYQr88i4XSKFG0ghmkpuUmR0gnxIhOfzN6fMkAY7dMIPrpYEviIPIJ9nZ+KkMvBXv80IQGhqjjaZCEENNaOGQKka/h4DfU/maePu+3xbSMk7un9TQ5waPZOwsoNwylPevbvQcqy/rzTBLaU+0Yl14htZ8y3G8i09y04p0GISQlaubpeb+0e9e1dWWvg5tsoYKiyTKVy5KHjvzNGLGSGEj5U8+09B/sSvhTjEiuIjPwJzSLx8oRXRsrsSt6u9SYR0xuO0Cdjnwx3xIu67tfaQOi/J7Meoo2q8p6+adGVOJQHsDRVCEqZc+0leorOUKIKUJMfh+jFQfcZHn94/TlfDJJ3w8Vkhzr+I8li4GCACmfsAgjBNUUR4uPtPUS1ltHK2oG94ErKFKQqYNaIyf/T5sXtpCcqSl2uxPzpQvK2oGqA35po3SwzKVIcOwG0Du6zca17kKIbDfUj/Tuvs= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR10MB1582.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(366004)(136003)(39860400002)(396003)(376002)(6506007)(83380400001)(6486002)(64756008)(110136005)(5660300002)(8936002)(8676002)(54906003)(7416002)(316002)(66556008)(91956017)(1076003)(186003)(66476007)(2906002)(4326008)(71200400001)(36756003)(26005)(122000001)(2616005)(6512007)(66946007)(478600001)(38100700002)(44832011)(86362001)(76116006)(66446008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata: =?iso-8859-1?q?NPBlHEnUgG85WhkzAy6ZEt++k?= =?iso-8859-1?q?138tubHOZrVSm3nVetXXrmkY6wm/rcVhlyAzko/W25WALMzRW+BCT1WfRtTp?= =?iso-8859-1?q?or6QaQuuD3rm37rskuVBlEbiOhWH8jVfbeVnJg3zlkxMVmLb6KvwZ9G7VHW0?= =?iso-8859-1?q?zKNBwnqnAroKHp4gLs7Hj6EIhsFurGs9mwdrsx3nfca72m8kf+/RXl5EFCeN?= =?iso-8859-1?q?AQUxgYJX5Mw0iW2meVXOqmT9kzadJXL2ZMMKxZZa1Q6jTZ3unRNpfF5ZXheO?= =?iso-8859-1?q?Rq7eRBFk5wjHDkGuZbgC38I5ME595JsPvEOz0FSL12FrOwe1bJb5YAeRk1WH?= =?iso-8859-1?q?xpZccTb78pX0OEDQVJoyLnFy5+KlvYNBYuNtZfmKDuclvS9E5tnWjs12IgrF?= =?iso-8859-1?q?vHrb5vLKhQpOK5TL72N2bwPuhJ+3796155ICnyaIkjWFxhyb+gA3kOFLW/vm?= =?iso-8859-1?q?f4Pp9yUwtl+OkjTXSwhIBX8oB1V/rr5xduMkrXkgyD5Vp8iB0dWK4yx7FgIt?= =?iso-8859-1?q?tgrlXl1juMZIyzSxUaK7xvYQOj3x1a9xt0zPYdeYKBY8LN3XTbp7+3Oo01TV?= =?iso-8859-1?q?vR8o+4oRfAQRQ5wQoa03rNPV3kutX7yd3YXG8gcBigopDmQiYracdSghV++e?= =?iso-8859-1?q?orRYY+WWjAE7pzhOpnHaMoVDac2/A7v4K27MkAgnTxFeFEK7yXiHWuzh0mZd?= =?iso-8859-1?q?+0kSKBxx2Uf1AzMui62c4MnI/V5r76plwLZR14dTzF+bedwlnSn3fN4Ccm3A?= =?iso-8859-1?q?mMQxDoHpjVnHk6CF/kbgUj1PCs9opB/MTmzNtFsFXaAKvxT6v0MRUReOEXvY?= =?iso-8859-1?q?b5oj7BvRrwNfx9IgFp/duQhSu6rzPcrhqpZp4LBGrF2Wn5V4F+5RYSKlZDab?= =?iso-8859-1?q?C9rbrCHgoJCPrXNkmvbNXgsN/mYilVgOuFU7EzgXcdawdc5yIqn0KRglvVEh?= =?iso-8859-1?q?c4XXFpFU8QFO7HniXAbDRJEmUm8HI2DDOYETXG38ItpQom2ef+xDYOeqIFpl?= =?iso-8859-1?q?Ua/apxHt53XP/dTWIpV0SWM1e16eVoCPO5r3/kEevaCEFqPYmOYBvMQmAsRx?= =?iso-8859-1?q?ydyFrEofgGoMXqWvFQkPFP2SpAmUOzyzqxI6mMX0oKpo1fSm05qACqeQpucS?= =?iso-8859-1?q?8u7gy5JAi60Gc8O61vg3DdX93A9A4vx5rdO2PGCVa8J8XeI3JWYd688K6Pij?= =?iso-8859-1?q?ErVMBg1Jq+8RnRpW4GVI+JvsagrcIkTCgK9SOo+9k3nBcWwRM/n7oAfPoI8K?= =?iso-8859-1?q?7oQjGKAXdF+0jzHJDuHBW5Mp8LOMUoVSlDvz6mT81VuOxo7pvfnsDR+EPmSE?= =?iso-8859-1?q?BMQL5mC6eUOpB1tXGQ51kNpkejXZE+qbBtGdul40zwdkwFl8g+vXISlRS+2?= MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR10MB1582.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 667a504d-3ed2-4e5f-7c57-08d9041c5ddf X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Apr 2021 16:50:12.8429 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: D9qXCdvovrjf9VinGe/UJqT/H3WoMinDhk6rZjZm+12kCme2UXbkva0deohqSy2thifru51k5ObMHXwc2j+Eig== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4772 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9960 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 phishscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104200117 X-Proofpoint-ORIG-GUID: tuDDPyW461aWiHkKAXJlI4tzj2P2zeAj X-Proofpoint-GUID: tuDDPyW461aWiHkKAXJlI4tzj2P2zeAj X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9960 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 bulkscore=0 phishscore=0 clxscore=1011 impostorscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104200117 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org arm64_notify_segfault() was written to decide on the si_code from the assembly emulation of the swp_handler(), but was also used for the signal generation from failed access_ok() and unaligned instructions. When access_ok() fails, there is no need to search for the offending address in the VMA space. Instead, simply set the error to SIGSEGV with si_code SEGV_ACCERR. Change the return code from emulate_swpX() when there is an unaligned pointer so the caller can differentiate from the EFAULT. It is unnecessary to search the VMAs in the case of an unaligned pointer. This change uses SIGSEGV and SEGV_ACCERR instead of SIGBUS to keep with what was returned before. Fixes: bd35a4adc413 (arm64: Port SWP/SWPB emulation support from arm) Signed-off-by: Liam R. Howlett Reported-by: kernel test robot --- arch/arm64/kernel/armv8_deprecated.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c index 0e86e8b9cedd..f424082b3455 100644 --- a/arch/arm64/kernel/armv8_deprecated.c +++ b/arch/arm64/kernel/armv8_deprecated.c @@ -324,7 +324,7 @@ static int emulate_swpX(unsigned int address, unsigned int *data, if ((type != TYPE_SWPB) && (address & 0x3)) { /* SWP to unaligned address not permitted */ pr_debug("SWP instruction on unaligned pointer!\n"); - return -EFAULT; + return -ENXIO; } while (1) { @@ -406,15 +406,17 @@ static int swp_handler(struct pt_regs *regs, u32 instr) user_ptr = (const void __user *)(unsigned long)(address & ~3); if (!access_ok(user_ptr, 4)) { pr_debug("SWP{B} emulation: access to 0x%08x not allowed!\n", - address); - goto fault; + address); + goto e_access; } res = emulate_swpX(address, &data, type); - if (res == -EFAULT) - goto fault; - else if (res == 0) + if (!res) regs->user_regs.regs[destreg] = data; + else if (res == -EFAULT) + goto e_fault; + else if (res = -ENXIO) /* Unaligned pointer */ + goto e_align; ret: if (type == TYPE_SWPB) @@ -428,10 +430,14 @@ static int swp_handler(struct pt_regs *regs, u32 instr) arm64_skip_faulting_instruction(regs, 4); return 0; -fault: +e_fault: pr_debug("SWP{B} emulation: access caused memory abort!\n"); arm64_notify_segfault(address); + return 0; +e_align: +e_access: + force_signal_inject(SIGSEGV, SEGV_ACCERR, address, 0); return 0; } From patchwork Tue Apr 20 16:50:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 12214693 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,PDS_BAD_THREAD_QP_64,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCD46C433ED for ; Tue, 20 Apr 2021 16:50:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0839613D4 for ; Tue, 20 Apr 2021 16:50:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233380AbhDTQvO (ORCPT ); Tue, 20 Apr 2021 12:51:14 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:56372 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233379AbhDTQvN (ORCPT ); Tue, 20 Apr 2021 12:51:13 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13KGYwGa110556; Tue, 20 Apr 2021 16:50:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=vizutN4qjOVBZgUbVWBMCtJcAIxkye7j89XvrdngMNI=; b=AGDUR5zimmUPVaeHznGvNZ7KYCOP08SsQgxckeXpEdRFedPD0/hqj3js2i3nj605vu1R 0AQZNV1bi03WvFbyOMSjsNkgmcuwcOTz/eoZJGF5KmP8bZpgP6vdp9yaRO4BRCUN7+5H kIGwYxR/tyty+X7PRhyC8TnTPkiH6Pbnwsta6Y+nF7vSFj1mvNO5+jgkWosdnT1O2jiz tmOXB2qyoigl7pOosAuwt3mE11ivOz26h3wlL7SW3nEMbHosVFxBKdZc0sOnx8myRU9W nWuV/8kzG4GpC6hgSmZEk8bZ+wbe9dW1AOe80tIjYjwU9Txhz36Uc0Az7P2lizAT6ik9 Xg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 37yqmnfuw2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Apr 2021 16:50:16 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13KGa7gL084073; Tue, 20 Apr 2021 16:50:16 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam08lp2043.outbound.protection.outlook.com [104.47.73.43]) by aserp3020.oracle.com with ESMTP id 3809k0n3gx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Apr 2021 16:50:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bfpqMCYUmxgKDfDk8ZiEYmC7h1S/5YkL7MGlTr86vW1fwBchqcQi7SecJYiHTP0+GTtvoBpbgC0UoL/E/lhpZVaoGKTCIxOO3vyWaR2BHJeXs5kzWnJPZvbg+n8QlTO62M6Z5+xEO0JwT5Gud/VGVCu7xV554goex7BLZfNfQl739V4nH/Xd616fWhcVt9xtpMMg92g/lzzvA2j2kC7DFasJ8qOz2eWePwHPckjfMYqOqP4Jy4bHtKQGgmF9UJWFGBunQY50xo/orpAmZsnnZ8V/Sf0i9QHrwJvNS6nM62ZWalRPCNBiHcka55ND1Sg13tMIL+NkSGnRNTXj/nUjHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vizutN4qjOVBZgUbVWBMCtJcAIxkye7j89XvrdngMNI=; b=d+zO0Pp/AlMQwaXFBrvKZuftS6sYuoVt6pgMf/2+amMkY7D3WWvg6dMJt0JOx9/UMoh2YzuMGPYQ2iNogtejKDACJsXO3Ei8YnNSvMVFWtpWE8nveTsz5F6WWLtcQLuDQpYDhTzaZyepsXU1oOb08cVPARLTbFLAND1R13pqPra+dv3nTUUWmcVT7tKLcjdG0qgO22Jh6vqc1rM/IkcmZL8/QW1meDHqWmDNaqpHndHi9hun0yyjbDQos98pSTR3jZvKtKaFdfe7O9qq8OMQWZlQy3fW4uQ3tZ2YDasH7xhWZIQFqxVspDSHNbp5mG6ce+Ufy9xlS5WsP9Wg2CrmyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vizutN4qjOVBZgUbVWBMCtJcAIxkye7j89XvrdngMNI=; b=OAWi4CfS9FEYc9yYcJWQesdmQ2ku0v2ra4gpI/fyQ8OWb+HpBRg7CUtDkXGOU5T/FX5dfr6Glxh1sMAer1c86+WVyzLewyRAQFVcGElq4XjEdPsWy8ovLtRspg5EX0Zud3iE5TnOZb0UwSmD0lVcs5LGTQy30quDh0CXaUOB/H0= Received: from MWHPR10MB1582.namprd10.prod.outlook.com (2603:10b6:300:22::8) by MWHPR10MB1536.namprd10.prod.outlook.com (2603:10b6:300:24::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Tue, 20 Apr 2021 16:50:13 +0000 Received: from MWHPR10MB1582.namprd10.prod.outlook.com ([fe80::353a:1802:6e91:1811]) by MWHPR10MB1582.namprd10.prod.outlook.com ([fe80::353a:1802:6e91:1811%8]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 16:50:13 +0000 From: Liam Howlett To: Catalin Marinas , Will Deacon , Julien Grall CC: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Liam Howlett , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH 2/3] arm64: signal: sigreturn() and rt_sigreturn() sometime returns the wrong signals Thread-Topic: [PATCH 2/3] arm64: signal: sigreturn() and rt_sigreturn() sometime returns the wrong signals Thread-Index: AQHXNgU7cqnWwo9uSUqkb8fv6D7LrA== Date: Tue, 20 Apr 2021 16:50:13 +0000 Message-ID: <20210420165001.3790670-2-Liam.Howlett@Oracle.com> References: <20210420165001.3790670-1-Liam.Howlett@Oracle.com> In-Reply-To: <20210420165001.3790670-1-Liam.Howlett@Oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.30.2 authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=oracle.com; x-originating-ip: [23.233.25.87] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e0744ab1-4791-486f-fa11-08d9041c5e57 x-ms-traffictypediagnostic: MWHPR10MB1536: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6790; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: +KaajMNyKAuGoiBXyqgLhZfqqvxfUx0WZrWCN9zsXnaqQjYKXs1nlvsDjfLzRogQG9DeX7jEXv/FRzbWBG/xzJ2q+mpI//BM0Y0d+zudrmHBqIvqdWR6XN2cpRE8c7H/+wRXVbFcGqEx8YiNasYoRNRblpJPd3XRHzdUZMKCrYRPlO2kNMUGw6VSf/bPLi5Wwerwyp3IikhXdhzMns9bMpaYBB3pkCQ/H0XhtFbfjRGgGzDctG1QHQcP0XpYUYB2CAMUbu3NRpiJeD3ZGKmBWqZ4GR5rhW33+XgWgqPi7gIod5fxgSNYHjmmVqYhqxCWSmUCi4mzgL8lGDKpyBKOpIne+tYM+7C0DZBidQnKj+MrMoFv9MKt9SFF06dIDl+pMljrh8ZOWnEVuyzQfM9LN9hB3eunbwOHmQ/l8IBrf4kNR+18fmeO/mug3k+ND+VahD9auMipOVAsPE4/SD32rlHyM2cQmDFPYS6yuC8eertWkqUVIrvelFobKRLqiZfsJ6Y9//qxmAxY7zKDmpMki6/sEIuefJ+ZqxPsu9J2psPRbuNprKibXLWeJLl5c4w0gf9YkGVI5ganmjd+p6dIleM5w86mG6bhbZAKCTnMEi0= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR10MB1582.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(39860400002)(366004)(396003)(136003)(376002)(83380400001)(64756008)(2906002)(5660300002)(44832011)(6506007)(186003)(71200400001)(66476007)(66946007)(316002)(7416002)(66556008)(91956017)(54906003)(8936002)(1076003)(26005)(76116006)(8676002)(110136005)(36756003)(2616005)(122000001)(86362001)(6512007)(66446008)(478600001)(6486002)(4326008)(38100700002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata: =?iso-8859-1?q?JWO11iNKoXGZT2kEEOnHJiHju?= =?iso-8859-1?q?aa5ep220k8G7xTwO+GHkYeBnmnCGoR3D/0NGOnKfKqmr5PFBw/M6+yqkwx4O?= =?iso-8859-1?q?x72l6Pt42+4Jct5p2paqxr0QHht/ax3r5QDL0g3j6cdG0Hf0InlGlkLxdfD+?= =?iso-8859-1?q?HruvGEqrQKwKp4ogRRjLzBNGKkdxVzj01dKmSRpdgrevfXVxerE9ryhhKBiU?= =?iso-8859-1?q?whOt2bMY9uiIh0mnU2dxXoWOI2AzOulCr5iieLz54cN7EFwckq5W/QcyIGXH?= =?iso-8859-1?q?3h1bKZRS9E9R8aR2KDDGVdjxp0uqI9T4S7qJXE8KlaYeZXQDEnrr8e3SJEn2?= =?iso-8859-1?q?etUMs4CHIVvUiFGMktN8aI+lKRIHR2KYjmi+Hi7QXlUZfrfRz5zkZidgIPVf?= =?iso-8859-1?q?JapP5pGbAirFNgPpgfXagEFjEoPGXWFGj2Y78JZgQemCSCepRNzvfFFimTmt?= =?iso-8859-1?q?aRsPMqXtoa5j20HShiGEx6z3dA3LIDN6myHgypb2DtBdGEB8DoUQlhmqQ4R1?= =?iso-8859-1?q?7CnU5A2eK3j2cNpNRSqaEwD9b+m5sOiLCvr6Y0P+x/BrQhU0Di5ALvXTTJTe?= =?iso-8859-1?q?kWzSuFhOMzVH7ETFfL0LoXZBCkldIw5IFN3z46xfvL2ypeMNWzUYKbb0b/gh?= =?iso-8859-1?q?8W7i3rbXdrSprRWErahtsM2lfon6Cz8q/N3oAPOeCgDiS/1bEHu+4Sgcv/aG?= =?iso-8859-1?q?KfercXvLyQfyfMv18KlAtbJ6o3tIsJXY8VQtI5P1XHTqrs9HlZFY1OEy5Jpj?= =?iso-8859-1?q?6kXdTioL20rFw3g4F5aQMcsG+TrBUgoasMRmH2O5ctPZuBpDIqfWa1wXI3ZV?= =?iso-8859-1?q?e3ZndvqSaXDZC1hmNqFEpSB11PvCjMfzJ+126Ztx6svjByNavxQhxlG0KoKi?= =?iso-8859-1?q?BQPhTHbTUqZ5xlya/ds/glUmn1vUBGA+79N+Zd2oY/xFB5bPWomSaI3DxQCL?= =?iso-8859-1?q?z8WniFOvk1iy3XWbjsbrCSRPGkfgzjpOV7wqvn+LteSZhwJwSsXTtaddUUla?= =?iso-8859-1?q?gPNmhMwOihU7qm3f/lBVTUdLFmfl5EFJO+Ms7EYGawnC4y7V1VVjbgAU2K6D?= =?iso-8859-1?q?mcWxJLi48vN4adDu8wGiwb/EsMW0XiAN53txuVPuX7mBbUExFopHXZaGV246?= =?iso-8859-1?q?havGKsAxW9QHR++EW8Md6FMC7E/77aMj7RsIr4rIclCkn4jhaxmumf77/cV+?= =?iso-8859-1?q?vQY6MtnGf/2RPQ6pR9XsTv0LMwbb2n9wy5wmpH0y1cqWwPLcp0pE5Ec9hwPP?= =?iso-8859-1?q?/POn9L29782+KZgS3Pq8mklSDPH6i4IlMfNBlmHaDt3ixqFwoalwyNa13wgz?= =?iso-8859-1?q?fFF1ZgI7E298qAN6GaN7cOOI07eAmoiE/8xXQQWnjQNDDmCPa8YqMkOSCcI?= MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR10MB1582.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0744ab1-4791-486f-fa11-08d9041c5e57 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Apr 2021 16:50:13.3897 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: laZ5VI74wb9uhFf2ZShI/3EYvuwIlpwp46iwZGb8YmG5AzcAF2u4s0t7e3wtW8C6iSnVcTlTYqv1JIlcPlnJvQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1536 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9960 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 malwarescore=0 suspectscore=0 phishscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104200117 X-Proofpoint-ORIG-GUID: YcnjrERkwVhP-xy0laVrSODAkpWcIFea X-Proofpoint-GUID: YcnjrERkwVhP-xy0laVrSODAkpWcIFea X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9960 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 adultscore=0 impostorscore=0 spamscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104200117 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org arm64_notify_segfault() was used to force a SIGSEGV in all error cases in sigreturn() and rt_sigreturn() to avoid writing a new sig handler. There is now a better sig handler to use which does not search the VMA address space and return a slightly incorrect error code. Restore the older and correct si_code of SI_KERNEL by using arm64_notify_die(). In the case of !access_ok(), simply return SIGSEGV with si_code SEGV_ACCERR. This change requires exporting arm64_notfiy_die() to the arm64 traps.h Fixes: f71016a8a8c5 (arm64: signal: Call arm64_notify_segfault when failing to deliver signal) Signed-off-by: Liam R. Howlett --- arch/arm64/include/asm/traps.h | 2 ++ arch/arm64/kernel/signal.c | 8 ++++++-- arch/arm64/kernel/signal32.c | 18 ++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/traps.h b/arch/arm64/include/asm/traps.h index 54f32a0675df..9b76144fcba6 100644 --- a/arch/arm64/include/asm/traps.h +++ b/arch/arm64/include/asm/traps.h @@ -29,6 +29,8 @@ void arm64_notify_segfault(unsigned long addr); void arm64_force_sig_fault(int signo, int code, unsigned long far, const char *str); void arm64_force_sig_mceerr(int code, unsigned long far, short lsb, const char *str); void arm64_force_sig_ptrace_errno_trap(int errno, unsigned long far, const char *str); +void arm64_notify_die(const char *str, struct pt_regs *regs, int signo, + int sicode, unsigned long far, int err); /* * Move regs->pc to next instruction and do necessary setup before it diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 6237486ff6bb..9fde6dc760c3 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -544,7 +544,7 @@ SYSCALL_DEFINE0(rt_sigreturn) frame = (struct rt_sigframe __user *)regs->sp; if (!access_ok(frame, sizeof (*frame))) - goto badframe; + goto e_access; if (restore_sigframe(regs, frame)) goto badframe; @@ -555,7 +555,11 @@ SYSCALL_DEFINE0(rt_sigreturn) return regs->regs[0]; badframe: - arm64_notify_segfault(regs->sp); + arm64_notify_die("Bad frame", regs, SIGSEGV, SI_KERNEL, regs->sp, 0); + return 0; + +e_access: + force_signal_inject(SIGSEGV, SEGV_ACCERR, regs->sp, 0); return 0; } diff --git a/arch/arm64/kernel/signal32.c b/arch/arm64/kernel/signal32.c index 2f507f565c48..af8b6c0eb8aa 100644 --- a/arch/arm64/kernel/signal32.c +++ b/arch/arm64/kernel/signal32.c @@ -248,7 +248,7 @@ COMPAT_SYSCALL_DEFINE0(sigreturn) frame = (struct compat_sigframe __user *)regs->compat_sp; if (!access_ok(frame, sizeof (*frame))) - goto badframe; + goto e_access; if (compat_restore_sigframe(regs, frame)) goto badframe; @@ -256,7 +256,12 @@ COMPAT_SYSCALL_DEFINE0(sigreturn) return regs->regs[0]; badframe: - arm64_notify_segfault(regs->compat_sp); + arm64_notify_die("Bad frame", regs, SIGSEGV, SI_KERNEL, + regs->compat_sp, 0); + return 0; + +e_access: + force_signal_inject(SIGSEGV, SEGV_ACCERR, regs->compat_sp, 0); return 0; } @@ -279,7 +284,7 @@ COMPAT_SYSCALL_DEFINE0(rt_sigreturn) frame = (struct compat_rt_sigframe __user *)regs->compat_sp; if (!access_ok(frame, sizeof (*frame))) - goto badframe; + goto e_access; if (compat_restore_sigframe(regs, &frame->sig)) goto badframe; @@ -290,7 +295,12 @@ COMPAT_SYSCALL_DEFINE0(rt_sigreturn) return regs->regs[0]; badframe: - arm64_notify_segfault(regs->compat_sp); + arm64_notify_die("Bad frame", regs, SIGSEGV, SI_KERNEL, + regs->compat_sp, 0); + return 0; + +e_access: + force_signal_inject(SIGSEGV, SEGV_ACCERR, regs->compat_sp, 0); return 0; } From patchwork Tue Apr 20 16:50:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 12214695 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,PDS_BAD_THREAD_QP_64,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26D75C433B4 for ; Tue, 20 Apr 2021 16:50:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD711613D3 for ; Tue, 20 Apr 2021 16:50:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233263AbhDTQvO (ORCPT ); Tue, 20 Apr 2021 12:51:14 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:56370 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233376AbhDTQvN (ORCPT ); Tue, 20 Apr 2021 12:51:13 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13KGYwqT110562; Tue, 20 Apr 2021 16:50:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=oDHmLqAsgLS7mPsMg0BXUPLJw+J0W7W2uM1tHebWINQ=; b=OWx65MZVJICIfSodKnIOK8CX0Lq2KK8HwZQ8+hwvleQa48M7Iz/S3X9O0UUS4ozJsnFn Tv5Dwk0aLC2flAjZB5dlkFRENokgBul9nSZHo1XWtSQlRhazj781FP3VUuZveOY6Pgps 4u9SeMGwjspECxV4RMJNxxmSRKUlOKhM14FXl+AAUqX+0aC1xKHoL138VnFlutZaS8h9 QeTGYSq8Pi+tlIPv7XWK4RSORkJB74UNJB7qkzo4TxHekEVlK/YrXV8HmFrtNrpSUXkq rR7UzjqVz/RQ/S+NcVfQv5HO6bDo91JW43kh+bY9aUq9EZBd5Sjoeu/pzz+KhgGDhuSo qQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 37yqmnfuw3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Apr 2021 16:50:17 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13KGa7gM084073; Tue, 20 Apr 2021 16:50:17 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam08lp2043.outbound.protection.outlook.com [104.47.73.43]) by aserp3020.oracle.com with ESMTP id 3809k0n3gx-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Apr 2021 16:50:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BKaBacitNyl+gvqZa9QVaR07iNOa8oqSJOXBie5r33lv5ztlxtX41/15xEwhw1C2FZ6S4zcqmjFbw1HQfPZ+8Nvy4eGzScojKS5fcgxtUqwm+diZH2wRPvcEGSK4dlX7MxlaoxSs/PJg7LjYYGtF6ubXvOm/K8mWtv3yUAZEsChLwqkjI6a8sb2GBs5Zi9U4Q3+ikuV+pMzbDYPfAWhYGIo/erWcxYnnAb5IMKW8Z0E1MDBl4vpkXnwqFYwDNH7l313mXWkE6b66HEh1vfOrhfkPfeuKLiKYDID4C+rHFgA5hBHWwQqKNVgcLqzlGaJPfoUhp7oUB9zsjfCkST6P+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oDHmLqAsgLS7mPsMg0BXUPLJw+J0W7W2uM1tHebWINQ=; b=dR/QX5EcpC7BEO0fy5u+mc/5s5jQXdb2Bspk8NJn9Sbs6xY/fsyi08C+OWSX44bCDu+/aa4BWIJ3rTzRg869l2WmgP2dJJjrl3dSreK22WWuaQbjITvCjmA1qb7Q2I2qCKFd8+oPYnlbvL7DwSffdV8SW/6E7WjER2y3jyfH/zSAjAf4hCpLjIyFvbZbA5qgyKMy4ad3/oyKf4FBKjxeVNOmf809Jix7/yHk29OcuPTDSvquk1aZPozy3xAVPg71wylgvZ2f4MvdRNiilaHvdQO1ZV9mtFJBl7HpwkDcNIvF7JBOCzbNxIbKOf/7/QzFjMQS7L3bFONJhiAsYmi1Mg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oDHmLqAsgLS7mPsMg0BXUPLJw+J0W7W2uM1tHebWINQ=; b=iXVcQRyfhEV8rBhfbndYrVclGMTbtn/4Mb3JGpMa6kvGeQl91CLVGeZpLa872sPWUkE3ranR1EfNmDJXdz4gZRWRkDo/BJddYB5ayApyPMTMbd99x4k6fL7lLhWL+xtxRNt5tr3XBZPWpzJo5Vb4Ipjp0IzFIiw2Hzsj68Nk4qE= Received: from MWHPR10MB1582.namprd10.prod.outlook.com (2603:10b6:300:22::8) by MWHPR10MB1536.namprd10.prod.outlook.com (2603:10b6:300:24::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Tue, 20 Apr 2021 16:50:14 +0000 Received: from MWHPR10MB1582.namprd10.prod.outlook.com ([fe80::353a:1802:6e91:1811]) by MWHPR10MB1582.namprd10.prod.outlook.com ([fe80::353a:1802:6e91:1811%8]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 16:50:14 +0000 From: Liam Howlett To: Catalin Marinas , Will Deacon , Julien Grall CC: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Liam Howlett , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH 3/3] arch/arm64/kernel/traps: Use find_vma_intersection() in traps for setting si_code Thread-Topic: [PATCH 3/3] arch/arm64/kernel/traps: Use find_vma_intersection() in traps for setting si_code Thread-Index: AQHXNgU7TopVgzWGUEaUH9orR8DEdw== Date: Tue, 20 Apr 2021 16:50:13 +0000 Message-ID: <20210420165001.3790670-3-Liam.Howlett@Oracle.com> References: <20210420165001.3790670-1-Liam.Howlett@Oracle.com> In-Reply-To: <20210420165001.3790670-1-Liam.Howlett@Oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.30.2 authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=oracle.com; x-originating-ip: [23.233.25.87] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0d829fda-db64-4971-fc26-08d9041c5e94 x-ms-traffictypediagnostic: MWHPR10MB1536: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: aP6pqR/WIteaIsHeiV1f2v0xyugwQXhOjRqKqK7UIFRQB82k3tYaNwrkMD3ppauNs35h7pa0TXhL43Y4V6pBmhfCrou7o7VejVhO1/rzD1nfVbMjrFEQL/l1L5rEBTesn7tqIb9nWv1UAVVz4uVMq6Nh+7T0oD0W/sndF/GlUaJG3bQX+wsWormbhoayTABod9nu8+pyKiNm5S2HJwE5CVtgGR6T0r1PG95bZHJ6WycqljbcZqknJf05PYLXwWvsy+sOsRp03OOXoEM6zw55v9T1W9bSgxu9lMEp/jgBcarg4JxZFF9h/aADK03h8cWaGHOObEolZHoMcmJ79xovw7fY1JNdSiBmbGv7QVuW9cYGASzImu53Q2YVOLc9XTHrWkWlh2n2JOOlptYuvl0IZSR1CO4YqI8EKnZYUEppMxSuHKuqkGu/gyzsb0K6r5wVDi+5qsEI62YQZCanq/1FxIfBImEqwHRzL3PvFlvFAOIkU1HD1vumtRGRgKGEsfHZBgBpDJgNaoXWfmlA04I3FcY0HKrt3kWd80F9FsPk43wklOo2LGjlEmLu6QmzfPwkwSdSu88vhipDeenS0oxYWDeulBQT8z9OTVbSDXCkqYM= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR10MB1582.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(39860400002)(366004)(396003)(136003)(376002)(83380400001)(64756008)(2906002)(5660300002)(44832011)(6506007)(186003)(71200400001)(66476007)(66946007)(316002)(7416002)(66556008)(91956017)(54906003)(8936002)(1076003)(26005)(76116006)(8676002)(110136005)(36756003)(2616005)(122000001)(86362001)(6512007)(66446008)(478600001)(6486002)(4326008)(38100700002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata: =?iso-8859-1?q?eAe8HF9r75jQP7W8UWVaznpVT?= =?iso-8859-1?q?Mmd+vC2PenTlfXFf+0Bz99jfZg/mfItAl6aXxzG9ynGfrHfLV0F696OHKinX?= =?iso-8859-1?q?PZFX4CLcmHCql/Skd7cF3d3fhjYlrKCfMxF1iIskF93sc4ZH968Vfchk8quJ?= =?iso-8859-1?q?R277BIV0nRDy4iIBJYt/XxQKiM3toJvgAlYWnXcFCeuC8kKSGAQtu8B80sXV?= =?iso-8859-1?q?HVOnrQge1W6bb5WFYI0BXpxhuWK80ISWk8ACgSUPgBQfPSHsFpJPuO5usQik?= =?iso-8859-1?q?f2cEumRKJDIkxIDmvAI8kS3XUGpkyYXa/TVrVjQY7soDsE78UVO17ZtfJLQ1?= =?iso-8859-1?q?Rdd+bxd7XSAACxHn0F05JKM6cp3u5MS4O9lQHIrY6dyvUGJpI7lbusrcC9RP?= =?iso-8859-1?q?7L70eRnc1YhmRXBCJbdHpQ1+sBQRQdnrJ76dWUaNehzZwUeW2udAX1QVKf6r?= =?iso-8859-1?q?iDuouGfPQgN3S1vU7i2N7Hi0iujl5j1qrDryw3A+onFdHOXezSdCFxow4XM3?= =?iso-8859-1?q?DUKNODvU8QcIlvkifUPftRj5PTqpQnu43TsQOhenwEQDQ5u5bS6Nzis3FwYy?= =?iso-8859-1?q?4d4m3xdfk29cZQ2E47gB809/yyVYXe8nlyZUXLH++Yad8oqjZqVI29MELV8E?= =?iso-8859-1?q?SigKMfi9cKvNGsWaYBKol8vPOvxdkNEwp+Fe42cJLZ20V9ZYUZKQfmvBo8wy?= =?iso-8859-1?q?73WPisnr+i7b6qs3NRH3OvvFdwiTGbUOcq8wrjr/1EhHiwq/HaCOWidD3kI+?= =?iso-8859-1?q?wCkbFKVbnUqEZFMWSFwZnO/2HfSFtYUH1f21CctVMeN9Z9oxicmDe3ndGtgG?= =?iso-8859-1?q?AA4gRzppz7ZR3C86Q9B8wDPLYvIFgzrLUMldFFbY+JAXGIAKLlc/i1kOG/W0?= =?iso-8859-1?q?7WhuDwzm5rFjnQRIgWRUwlLnERHRTcqrubRThOvuw9pR15AEtMD/wnStKJEj?= =?iso-8859-1?q?ca+cC7HU1sCGlT6fZ+A3bN37HDfRUB2K7b38HynRvGOIkYIPbwCXa3zaYWEl?= =?iso-8859-1?q?qar7qCVV8bqRbKIGjLR4aPMKyb7AWi4IvgF30ZrlMyBiU6Uhh5w97gzUCxM8?= =?iso-8859-1?q?dS5uonVtxCZMkqB7yMewnQHZVTkm4cFc9yHk3WKJk2euAILbuiBaUzEnUwWp?= =?iso-8859-1?q?+OcHCZ9B/BmcfXMruJ3Rytsm8QbpuvtId+053ab+AVGHcOW9bwhlbB0ZTROd?= =?iso-8859-1?q?75M2HTlupd6YcYYrIHbkMufbH0TTBRVt7GpB7/4u7WVAiHBf7A/LOdL65i50?= =?iso-8859-1?q?M0XwXBWJyIZy9dKH7BaMZpW6oTuJazv9sN6SaUbcj3vstf3nxmWKtk3WwwZF?= =?iso-8859-1?q?rask/b+HND9XfBozQN59mhrE2VRmHcqrlAPnlViRAKc2/cAdeOizXF5wY8f?= MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR10MB1582.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d829fda-db64-4971-fc26-08d9041c5e94 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Apr 2021 16:50:13.8425 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: UHAnPyoKhs4auSck29MgX2MYyi9+gjr7bv21FIfbedFBxIOo+TRlU2Wdb8scM8HfztUFvHyqKOcaqz3H111xBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1536 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9960 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 malwarescore=0 suspectscore=0 phishscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104200117 X-Proofpoint-ORIG-GUID: DlUi-Rm3_w_lNpuqS41IgthNEHYqyDNw X-Proofpoint-GUID: DlUi-Rm3_w_lNpuqS41IgthNEHYqyDNw X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9960 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 adultscore=0 impostorscore=0 spamscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104200117 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org find_vma() will continue to search upwards until the end of the virtual memory space. This means the si_code would almost never be set to SEGV_MAPERR even when the address falls outside of any VMA. The result is that the si_code is not reliable as it may or may not be set to the correct result, depending on where the address falls in the address space. Using find_vma_intersection() allows for what is intended by only returning a VMA if it falls within the range provided, in this case a window of 1. Fixes: bd35a4adc413 (arm64: Port SWP/SWPB emulation support from arm) Signed-off-by: Liam R. Howlett --- arch/arm64/kernel/traps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index a05d34f0e82a..a44007904a64 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -383,9 +383,10 @@ void force_signal_inject(int signal, int code, unsigned long address, unsigned i void arm64_notify_segfault(unsigned long addr) { int code; + unsigned long ut_addr = untagged_addr(addr); mmap_read_lock(current->mm); - if (find_vma(current->mm, untagged_addr(addr)) == NULL) + if (find_vma_intersection(current->mm, ut_addr, ut_addr + 1) == NULL) code = SEGV_MAPERR; else code = SEGV_ACCERR;