From patchwork Mon Apr 9 00:24:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10328857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C25A86037F for ; Mon, 9 Apr 2018 00:30:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3C1D2884C for ; Mon, 9 Apr 2018 00:30:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A77A42891D; Mon, 9 Apr 2018 00:30:52 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D45052884C for ; Mon, 9 Apr 2018 00:30:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fFzxBhm+E4Xx1+fjnWeMAU+n37vcp2e70ESz7L7knbc=; b=AGlWK9b5tBIioP Xz5ZNWr0/d1n7USCd89mqfCvF4SInFqAKcRjHSQTA+RuadGsS5SWvjwaqPE6tfvpcNWJQwoJ35BLh v4NRsDQ9zL27SmKJQLkWjj3FIUdEEz/559W4pUoBTEa5qEkhT/zJyd1Wf+wnmePinAsLN51NDVW1I Ht5uOpvo4/rlGfiUdqx98HjT1cffXNUNuofZk22o6whptifSBUd7I+LvJXepNPOOB8DkML0k9s4b8 bw3mwY5t3ET4XdG8reLs4cuDcSDg/nrpACjDzDkbAEp4K1Saxd47AebBD2Lkr0kkBGtGG+uE21n9S zKrzoF1Us+JYUkvyN+sA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5Khk-00067a-9S; Mon, 09 Apr 2018 00:30:40 +0000 Received: from mail-sn1nam02on0099.outbound.protection.outlook.com ([104.47.36.99] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5Kgy-0004QU-TJ for linux-arm-kernel@lists.infradead.org; Mon, 09 Apr 2018 00:29:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=iBlo8gH/JUphDUPtlWiMT2YIbxmYl6Fi8ynxFFsAAIg=; b=SdPwtQH3+Xl9tDPA0dqsD101CDowcdO7Gr0VF4DGBQZl0jphC0aBM5D9CFbkwsRSDPyjpqjV5/vLXF5pQjnt0vHb8S4kXHGSBwATyZkwGYO97ytgbeo4AFCD99mlPCh7CUm258kgqkOEtiHwNJNatzPkBK9L20dO/PZJk+nmZeE= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:29:37 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:29:37 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH AUTOSEL for 4.9 112/293] ARM: 8683/1: ARM32: Support mremap() for sigpage/vDSO Thread-Topic: [PATCH AUTOSEL for 4.9 112/293] ARM: 8683/1: ARM32: Support mremap() for sigpage/vDSO Thread-Index: AQHTz5kaC2hKut03i0aHrsPlVgZBOw== Date: Mon, 9 Apr 2018 00:24:21 +0000 Message-ID: <20180409002239.163177-112-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM5PR2101MB1032; 7:KqI9Y8atOkKq76Fg2OeNP3C+usstaQv5Eh8qtZ2IBZKPvCelvuldsuv6f1rx0R7g2Xu6VTpGd/CIecqbPQoMDyufDWrrExCgqOan5XJ9heKkBghskIV2KQDGIkowcpq7hV++fvxPs67Y412TXKE1dASrfrEWw4Ak2b0m46n6cehRqMnvgc/mpCywbP3zQG49UMP8YwHjstt2kl/fBigN12/6fT1LOH1QrUBQRqF7puMi+CBZqt+1mosmzmzvpKSC; 20:wWyVQ3PE/04f6ZQzPElwOaYFONnw6STWOVRAe2X1WQ9MQJVnLfCaXmrcIiSvMwwOQT3LEn51AOz+La1ZnJFZCE59pul6NTxwplJTf4abM4QYNcfhPHSuE/nu03SsgYSCnH93OU+jTXUHtvkPp+u5mI/OJqIqReBKz+SsAcJdCJs= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 4d53ab3d-72d6-4ff2-27de-08d59db0fa11 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020); SRVR:DM5PR2101MB1032; x-ms-traffictypediagnostic: DM5PR2101MB1032: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(180628864354917)(89211679590171)(258649278758335); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3002001)(3231221)(944501327)(52105095)(10201501046)(93006095)(93001095)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:DM5PR2101MB1032; BCL:0; PCL:0; RULEID:; SRVR:DM5PR2101MB1032; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39380400002)(346002)(396003)(39860400002)(376002)(366004)(189003)(199004)(5660300001)(76176011)(99286004)(10090500001)(2900100001)(105586002)(305945005)(7736002)(107886003)(2501003)(5250100002)(14454004)(53936002)(4326008)(8936002)(68736007)(25786009)(86612001)(3846002)(66066001)(1076002)(486006)(316002)(72206003)(22452003)(106356001)(186003)(97736004)(6436002)(6116002)(476003)(2616005)(478600001)(6486002)(10290500003)(2906002)(110136005)(54906003)(7416002)(6512007)(81156014)(81166006)(8676002)(36756003)(11346002)(3660700001)(446003)(6666003)(86362001)(26005)(102836004)(575784001)(3280700002)(6506007)(59450400001)(22906009)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB1032; H:DM5PR2101MB1032.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 05ONDTU9hDWkczn/U70loxylNB0L/jBLj1LdmPEJkzvXStzuaEpZcUAl8eWwulB+zivifHXFu9ycZpXeEP/wSKn4DN5iMZKs86FK18HDuC/oRfbfO/Wt3CqfOhywOPjjfxjK2Ag7G0zLOL7muYr1sbFXiY/XLJEkUTurq4X235gNoQXwg4UtwY0SGvthEhnbx820fDYm09/jZt+lh0WUqO5jnK8N9GbmYKIr9i7bYpQRTV2oWqp5o8lRO/dVVgwvaAqAHjH1wz5zvZ1ap27hS97m9KrO6gf4vPUi6m2Zt/X0i3N9FPLg8UHyxKuvYmwh3wHmwzAjvScd20iXe7bBVj6wARJOBOq/2jP7zQXJ7vMlCgzlEn0xen+lv73YHyQufSXGo2H/k3SNAl3SCWcLyGjE56Yz7s17GY7amh5bFeU= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d53ab3d-72d6-4ff2-27de-08d59db0fa11 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:24:21.0500 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1032 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180408_172953_026290_1BF71574 X-CRM114-Status: GOOD ( 18.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Safonov , Will Deacon , Sasha Levin , Russell King , Christopher Covington , Cyrill Gorcunov , Thomas Gleixner , "linux-arm-kernel@lists.infradead.org" , Pavel Emelyanov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dmitry Safonov [ Upstream commit 280e87e98c09b85b617c7b2752c8b504c4ea98f6 ] CRIU restores application mappings on the same place where they were before Checkpoint. That means, that we need to move vDSO and sigpage during restore on exactly the same place where they were before C/R. Make mremap() code update mm->context.{sigpage,vdso} pointers during VMA move. Sigpage is used for landing after handling a signal - if the pointer is not updated during moving, the application might crash on any signal after mremap(). vDSO pointer on ARM32 is used only for setting auxv at this moment, update it during mremap() in case of future usage. Without those updates, current work of CRIU on ARM32 is not reliable. Historically, we error Checkpointing if we find vDSO page on ARM32 and suggest user to disable CONFIG_VDSO. But that's not correct - it goes from x86 where signal processing is ended in vDSO blob. For arm32 it's sigpage, which is not disabled with `CONFIG_VDSO=n'. Looks like C/R was working by luck - because userspace on ARM32 at this moment always sets SA_RESTORER. Signed-off-by: Dmitry Safonov Acked-by: Andy Lutomirski Cc: linux-arm-kernel@lists.infradead.org Cc: Will Deacon Cc: Thomas Gleixner Cc: Cyrill Gorcunov Cc: Pavel Emelyanov Cc: Christopher Covington Signed-off-by: Russell King Signed-off-by: Sasha Levin --- arch/arm/kernel/process.c | 8 ++++++++ arch/arm/kernel/vdso.c | 18 ++++++++++++++++++ arch/x86/entry/vdso/vma.c | 3 --- mm/mmap.c | 4 ++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c index 91d2d5b01414..ca4a3c0f04c6 100644 --- a/arch/arm/kernel/process.c +++ b/arch/arm/kernel/process.c @@ -401,9 +401,17 @@ static unsigned long sigpage_addr(const struct mm_struct *mm, static struct page *signal_page; extern struct page *get_signal_page(void); +static int sigpage_mremap(const struct vm_special_mapping *sm, + struct vm_area_struct *new_vma) +{ + current->mm->context.sigpage = new_vma->vm_start; + return 0; +} + static const struct vm_special_mapping sigpage_mapping = { .name = "[sigpage]", .pages = &signal_page, + .mremap = sigpage_mremap, }; int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) diff --git a/arch/arm/kernel/vdso.c b/arch/arm/kernel/vdso.c index 53cf86cf2d1a..a4d6dc0f2427 100644 --- a/arch/arm/kernel/vdso.c +++ b/arch/arm/kernel/vdso.c @@ -54,8 +54,26 @@ static const struct vm_special_mapping vdso_data_mapping = { .pages = &vdso_data_page, }; +static int vdso_mremap(const struct vm_special_mapping *sm, + struct vm_area_struct *new_vma) +{ + unsigned long new_size = new_vma->vm_end - new_vma->vm_start; + unsigned long vdso_size; + + /* without VVAR page */ + vdso_size = (vdso_total_pages - 1) << PAGE_SHIFT; + + if (vdso_size != new_size) + return -EINVAL; + + current->mm->context.vdso = new_vma->vm_start; + + return 0; +} + static struct vm_special_mapping vdso_text_mapping __ro_after_init = { .name = "[vdso]", + .mremap = vdso_mremap, }; struct elfinfo { diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c index 23c881caabd1..2f10de80d76c 100644 --- a/arch/x86/entry/vdso/vma.c +++ b/arch/x86/entry/vdso/vma.c @@ -76,9 +76,6 @@ static int vdso_mremap(const struct vm_special_mapping *sm, if (image->size != new_size) return -EINVAL; - if (WARN_ON_ONCE(current->mm != new_vma->vm_mm)) - return -EFAULT; - vdso_fix_landing(image, new_vma); current->mm->context.vdso = (void __user *)new_vma->vm_start; diff --git a/mm/mmap.c b/mm/mmap.c index 45ac5b973459..cdef4ae94b10 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3168,8 +3168,12 @@ static int special_mapping_mremap(struct vm_area_struct *new_vma) { struct vm_special_mapping *sm = new_vma->vm_private_data; + if (WARN_ON_ONCE(current->mm != new_vma->vm_mm)) + return -EFAULT; + if (sm->mremap) return sm->mremap(sm, new_vma); + return 0; }