From mboxrd@z Thu Jan 1 00:00:00 1970 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=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 E438AC2D0A3 for ; Tue, 3 Nov 2020 17:11:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4073F20E65 for ; Tue, 3 Nov 2020 17:11:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="ZxIx8/86" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4073F20E65 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B2B876B0068; Tue, 3 Nov 2020 12:11:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ADC426B006E; Tue, 3 Nov 2020 12:11:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97B816B0070; Tue, 3 Nov 2020 12:11:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id 6D1526B0068 for ; Tue, 3 Nov 2020 12:11:41 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 001501EE6 for ; Tue, 3 Nov 2020 17:11:40 +0000 (UTC) X-FDA: 77443748802.28.straw25_1709c4e272ba Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 49C036C36 for ; Tue, 3 Nov 2020 17:11:40 +0000 (UTC) X-HE-Tag: straw25_1709c4e272ba X-Filterd-Recvd-Size: 7367 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Tue, 3 Nov 2020 17:11:37 +0000 (UTC) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0A3H4rTv155482; Tue, 3 Nov 2020 12:11:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=7t6VQbq+UBMcFU+y3HOIFcGYkl/sQCQCIRqMqJzFNpU=; b=ZxIx8/86AdM8NgrtMHAVOjSE6ZucjR7JjpHqJFK4zf3I5/OfRhgUeMtrsKmJ36ffpf8k C9NBHxjYr6tPsuYbqckjzu+mdPKPYwsXiTS28uY/noqrWhLUsUEmTQ0GA0r1l+eX/khz UDXJHJM+LzTy6iKiXxqnBbeiiF4MxrqTfNRvlrOaR4HXaVemD403g0cuH69dMTwgM974 t/GR8iR4Lw4gCuvgMwKkCbyJn7hl6oTRjBpiwEScxTpLZLs9/Z4oqpBs7qQHLS3za7Tr IRheA2KlZd0TpHHUOfSCMFnO7tTYtzKhnlCmyxCVvLNH54jWhLl29qoIsjnJ33fCsdo6 Rw== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 34k12uuv2r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Nov 2020 12:11:21 -0500 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0A3H7Qhh018964; Tue, 3 Nov 2020 17:11:19 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03ams.nl.ibm.com with ESMTP id 34hm6haqfp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Nov 2020 17:11:18 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0A3HBGxE2687652 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Nov 2020 17:11:16 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A1B51A4055; Tue, 3 Nov 2020 17:11:16 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 19EC4A404D; Tue, 3 Nov 2020 17:11:16 +0000 (GMT) Received: from pomme.local (unknown [9.145.79.178]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 3 Nov 2020 17:11:16 +0000 (GMT) Subject: Re: [PATCH] x86/mpx: fix recursive munmap() corruption To: Christophe Leroy , Michael Ellerman Cc: Dave Hansen , Thomas Gleixner , Dave Hansen , mhocko@suse.com, rguenther@suse.de, x86@kernel.org, LKML , stable@vger.kernel.org, luto@amacapital.net, linux-mm@kvack.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org, vbabka@suse.cz References: <20190401141549.3F4721FE@viggo.jf.intel.com> <87d0lht1c0.fsf@concordia.ellerman.id.au> <6718ede2-1fcb-1a8f-a116-250eef6416c7@linux.vnet.ibm.com> <4f43d4d4-832d-37bc-be7f-da0da735bbec@intel.com> <4e1bbb14-e14f-8643-2072-17b4cdef5326@linux.vnet.ibm.com> <87k1faa2i0.fsf@concordia.ellerman.id.au> <9c2b2826-4083-fc9c-5a4d-c101858dd560@linux.vnet.ibm.com> <12313ba8-75b5-d44d-dbc0-0bf2c87dfb59@csgroup.eu> From: Laurent Dufour Message-ID: <452b347c-0a86-c710-16ba-5a98c12a47e3@linux.vnet.ibm.com> Date: Tue, 3 Nov 2020 18:11:15 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: <12313ba8-75b5-d44d-dbc0-0bf2c87dfb59@csgroup.eu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-03_08:2020-11-03,2020-11-03 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 clxscore=1011 impostorscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011030110 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Le 23/10/2020 =C3=A0 14:28, Christophe Leroy a =C3=A9crit=C2=A0: > Hi Laurent >=20 > Le 07/05/2019 =C3=A0 18:35, Laurent Dufour a =C3=A9crit=C2=A0: >> Le 01/05/2019 =C3=A0 12:32, Michael Ellerman a =C3=A9crit=C2=A0: >>> Laurent Dufour writes: >>>> Le 23/04/2019 =C3=A0 18:04, Dave Hansen a =C3=A9crit=C2=A0: >>>>> On 4/23/19 4:16 AM, Laurent Dufour wrote: >>> ... >>>>>> There are 2 assumptions here: >>>>>> =C2=A0=C2=A0 1. 'start' and 'end' are page aligned (this is guaran= teed by=20 >>>>>> __do_munmap(). >>>>>> =C2=A0=C2=A0 2. the VDSO is 1 page (this is guaranteed by the unio= n vdso_data_store=20 >>>>>> on powerpc) >>>>> >>>>> Are you sure about #2?=C2=A0 The 'vdso64_pages' variable seems rath= er >>>>> unnecessary if the VDSO is only 1 page. ;) >>>> >>>> Hum, not so sure now ;) >>>> I got confused, only the header is one page. >>>> The test is working as a best effort, and don't cover the case where >>>> only few pages inside the VDSO are unmmapped (start > >>>> mm->context.vdso_base). This is not what CRIU is doing and so this w= as >>>> enough for CRIU support. >>>> >>>> Michael, do you think there is a need to manage all the possibility >>>> here, since the only user is CRIU and unmapping the VDSO is not a so >>>> good idea for other processes ? >>> >>> Couldn't we implement the semantic that if any part of the VDSO is >>> unmapped then vdso_base is set to zero? That should be fairly easy, e= g: >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0if (start < vdso_end && end >=3D mm->context.= vdso_base) >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mm->context.vdso_base =3D = 0; >>> >>> >>> We might need to add vdso_end to the mm->context, but that should be = OK. >>> >>> That seems like it would work for CRIU and make sense in general? >> >> Sorry for the late answer, yes this would make more sense. >> >> Here is a patch doing that. >> >=20 > In your patch, the test seems overkill: >=20 > +=C2=A0=C2=A0=C2=A0 if ((start <=3D vdso_base && vdso_end <=3D end) ||=C2= =A0 /* 1=C2=A0=C2=A0 */ > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (vdso_base <=3D start && st= art < vdso_end) || /* 3,4 */ > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (vdso_base < end && end <=3D= vdso_end))=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* 2,3 */ > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mm->context.vdso_base =3D m= m->context.vdso_end =3D 0; >=20 > What about >=20 > =C2=A0=C2=A0=C2=A0=C2=A0if (start < vdso_end && vdso_start < end) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mm->context.vdso_base =3D m= m->context.vdso_end =3D 0; >=20 > This should cover all cases, or am I missing something ? >=20 >=20 > And do we really need to store vdso_end in the context ? > I think it should be possible to re-calculate it: the size of the VDSO = should be=20 > (&vdso32_end - &vdso32_start) + PAGE_SIZE for 32 bits VDSO, and (&vdso6= 4_end -=20 > &vdso64_start) + PAGE_SIZE for the 64 bits VDSO. Thanks Christophe for the advise. That is covering all the cases, and indeed is similar to the Michael's pr= oposal=20 I missed last year. I'll send a patch fixing this issue following your proposal. Cheers, Laurent.