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=-11.9 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 BCBD9C4741F for ; Mon, 28 Sep 2020 12:14:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 165D921D7F for ; Mon, 28 Sep 2020 12:14:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RYu5+Otf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 165D921D7F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 245906B005D; Mon, 28 Sep 2020 08:14:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F5136B0062; Mon, 28 Sep 2020 08:14:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10AFA6B0068; Mon, 28 Sep 2020 08:14:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0075.hostedemail.com [216.40.44.75]) by kanga.kvack.org (Postfix) with ESMTP id ED5376B005D for ; Mon, 28 Sep 2020 08:14:39 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A6031181AE86B for ; Mon, 28 Sep 2020 12:14:39 +0000 (UTC) X-FDA: 77312363478.15.meal88_3c1569327181 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 7FD581814B0C1 for ; Mon, 28 Sep 2020 12:14:39 +0000 (UTC) X-HE-Tag: meal88_3c1569327181 X-Filterd-Recvd-Size: 3840 Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Mon, 28 Sep 2020 12:14:38 +0000 (UTC) Received: by mail-ej1-f66.google.com with SMTP id r7so8136261ejs.11 for ; Mon, 28 Sep 2020 05:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=ULrSf82cVDYxU3BYbb7m6MDttIpV3C4Y47Llm1GUmmM=; b=RYu5+Otf5FEX6f56j8YIX5wR0ismZYUj9KwUidK4Ky/3nHe91MMusAiJHvYtzUj3ZS 83Blo43RlqTcu00g7T/v2HJeD7FskeRP5dKU8uqUL7sROkb7zAD4jFpx05gofs/9FmK4 GoeBfl1scYDfuGddxFU7mhF22O8A3jiCEp7YBrBSkp3TcbfPQqdr+l7cOYHX/trJL9d7 6IT/QtfYLj3AvCfxnC/ss8B4FceydqW4DLBQ4NAL21+37tB3ZCs7UEJlFStEJHdBV+/m oxxi0goCOQHHK6M68btJy2raPmpyXwT9kBNbXdVmrBk5lzSMmHeeFmAPZCk2jTh/f9Ft H2jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=ULrSf82cVDYxU3BYbb7m6MDttIpV3C4Y47Llm1GUmmM=; b=RA1dqh9y2B9chq6PRunfrv7I0bThL/GB7G2JjNXR1rQ4LQFSdUPTlX3TETWVlxL4cc 8YCWMkLUE0YJXRLjr0qsG/yChXHDCjV+1bbJnfyfUPhvDO8SjhFR9pIxdOfNI5Y3AvR8 7nK3TmNDEfcuJI0M8hzDk6ONlGkZfor0gDSuz11H49894hYtlQrUqWVKLMV/POILJx2y QmzOcUx+Nz6arbI0JoQelhx5VgO256OXAz4i4pzdrdcxxmZBcyXk/SY40sZzmtB3zS7+ yJZam54oTFBsvdV6RYiTU8PKqlEJby1P8jDg2zd0IXu/MojwiJWGDvv9sRPaR0l0pgY9 2WWA== X-Gm-Message-State: AOAM532aYTEBhkAc8T4udlLp5qW4uRATFi4xjZLxz9wE9elOe7fg7Doj t0BuugkFXmJIkrcqzw32vY0+lKWU+uflNwNkUUzp+A== X-Google-Smtp-Source: ABdhPJzyXErbSkHAJICjNnqPWiqQnKU0mMtCMTF0AauvxqADR4UegaiDlNtrxhZJCdOOpXcvF6uv/dIltrwioMVI26E= X-Received: by 2002:a17:906:f6c9:: with SMTP id jo9mr1312638ejb.233.1601295277452; Mon, 28 Sep 2020 05:14:37 -0700 (PDT) MIME-Version: 1.0 From: Jann Horn Date: Mon, 28 Sep 2020 14:14:11 +0200 Message-ID: Subject: SPARC version of arch_validate_prot() looks broken (UAF read) To: "David S. Miller" , sparclinux@vger.kernel.org, Linux-MM , Khalid Aziz , Khalid Aziz Cc: kernel list , Anthony Yznaga , Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.015970, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: >From what I can tell from looking at the code: 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. 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? 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? (Luckily the ordering of the vmacache operations works out such 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.)