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=-6.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 8E6C3C47420 for ; Tue, 29 Sep 2020 17:30:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6AC97208FE for ; Tue, 29 Sep 2020 17:30:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="PveahHWi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6AC97208FE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5C9ED6B005C; Tue, 29 Sep 2020 13:30:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 553326B005D; Tue, 29 Sep 2020 13:30:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CC976B0062; Tue, 29 Sep 2020 13:30:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1F8DC6B005C for ; Tue, 29 Sep 2020 13:30:23 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6EE8C127B for ; Tue, 29 Sep 2020 17:30:22 +0000 (UTC) X-FDA: 77316787884.15.rose44_1c15c822718c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 4542D1814B0C1 for ; Tue, 29 Sep 2020 17:30:22 +0000 (UTC) X-HE-Tag: rose44_1c15c822718c X-Filterd-Recvd-Size: 5535 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Sep 2020 17:30:21 +0000 (UTC) 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 08THO5Tc000826; Tue, 29 Sep 2020 17:30:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=x10vdcZygFwBhAQKwQ8d/UINuRe4BBcPPbo1w9Cq3eU=; b=PveahHWiqwegGPiJW675ylIuI/iLJfewyMLwqXzBr/mDiAJDZc4KEcjnCGsDcvZzF52a vfUaXxYJNBrV/c+iEVVvoEO/B5Or+uWmbpLgcemqMfSoY5WjY2Iiyo7PyuN0QtTrpBgR ebCUhOBVBqo3jcoz1w3HZ1s4tTNdj1tv20+YZArZW0L0ZpxCROddjUiviVsvMsHh4RsP phW73phmZSoI8iK2bF9+bmox9EbCHc+Fnq73dYzRVMemSnw2wq44CurSX7DmOhykHRZz /Dz7VMkRp7t5n5HBkLN/P63BXjJQ53FwYoUYjtPpkQYRmqPM/WRVIergto8H+pqpkXKr 0Q== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 33swkkv8af-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 29 Sep 2020 17:30:15 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08THOsTQ073592; Tue, 29 Sep 2020 17:30:15 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 33uv2e7cd0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Sep 2020 17:30:15 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 08THUAqZ031610; Tue, 29 Sep 2020 17:30:10 GMT Received: from [10.154.161.108] (/10.154.161.108) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 29 Sep 2020 10:30:09 -0700 Subject: Re: SPARC version of arch_validate_prot() looks broken (UAF read) To: Jann Horn , "David S. Miller" , sparclinux@vger.kernel.org, Linux-MM , Khalid Aziz Cc: kernel list , Anthony Yznaga , Andrew Morton References: From: Khalid Aziz Organization: Oracle Corp X-Pep-Version: 2.0 Message-ID: <0fb905cc-77a2-4beb-dc9c-0c2849a6f0ae@oracle.com> Date: Tue, 29 Sep 2020 11:30:07 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9759 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 adultscore=0 suspectscore=2 malwarescore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009290148 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9759 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 phishscore=0 suspectscore=2 mlxlogscore=999 clxscore=1011 priorityscore=1501 impostorscore=0 lowpriorityscore=0 bulkscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009290148 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: On 9/28/20 6:14 AM, Jann Horn wrote: > From what I can tell from looking at the code: >=20 > SPARC's arch_validate_prot() looks up the VMA and peeks at it; that's > not permitted though. do_mprotect_pkey() calls arch_validate_prot() > before taking the mmap lock, so we can hit use-after-free reads if > someone concurrently deletes a VMA we're looking at. That makes sense. It will be a good idea to encapsulate vma access inside sparc_validate_prot() between mmap_read_lock() and mmap_read_unlock(). >=20 > Additionally, arch_validate_prot() currently only accepts the start > address as a parameter, but the SPARC code probably should be checking > the entire given range, which might consist of multiple VMAs? >=20 > I'm not sure what the best fix is here; it kinda seems like what SPARC > really wants is a separate hook that is called from inside the loop in > do_mprotect_pkey() that iterates over the VMAs? So maybe commit > 9035cf9a97e4 ("mm: Add address parameter to arch_validate_prot()") > should be reverted, and a separate hook should be created? >=20 > (Luckily the ordering of the vmacache operations works out suIch that > AFAICS, despite calling find_vma() without holding the mmap_sem, we > can never end up establishing a vmacache entry with a dangling pointer > that might be considered valid on a subsequent call. So this should be > limited to a rather boring UAF data read, and not be exploitable for a > UAF write or UAF function pointer read.) >=20 I think arch_validate_prot() is still the right hook to validate the protection bits. sparc_validate_prot() can iterate over VMAs with read lock. This will, of course, require range as well to be passed to arch_validate_prot(). Thanks, Khalid