From nobody Thu Apr 16 03:43:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0639C433FE for ; Wed, 23 Nov 2022 18:14:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239504AbiKWSOE (ORCPT ); Wed, 23 Nov 2022 13:14:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239406AbiKWSNa (ORCPT ); Wed, 23 Nov 2022 13:13:30 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95798248C3 for ; Wed, 23 Nov 2022 10:08:24 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id e12-20020a62aa0c000000b0056c12c0aadeso11480609pff.21 for ; Wed, 23 Nov 2022 10:08:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=ZhRYpgjyXSj58WhO81SjAEi8hSt+BCz5HFDcwIe8pM8=; b=eemCHDnPT999d32SWZB6wMX6suDtePfunnKNAKvzoIn3dNciBQ3Ljfi3yTquKoy4zi pcrK20E0xXlpAUqIBXCsUy2HESlz6t7owcjQppn946VULCvKTSBqzveGqfypNqgpNaj6 iXJJ06APrWP4InCRCTIf8kHE2/VDWVF+MFQq0ndYTrBiNiLs+FjRyPNEHDsG5r2ooIeI CsiIDq8CprGQJ677tUo/JkB1kA7RBtQGesqHsnudWvHEOOVStEsMkrcTe8XMdiBbDUUr Wvup2PTocsoLNg5b9xVg9/tSx6vcK13d6i/NYpDI5r7NH1ZyRGnIfOvOepA7ESo1xmo0 LQrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ZhRYpgjyXSj58WhO81SjAEi8hSt+BCz5HFDcwIe8pM8=; b=rrA/vhMaYFBsgDmnfTeBiSxjbchdan/avu1O32/yn5kDqV8nG94qpPcZKjKLwDUglg bAskeV0sn47kdLBvGjPDa3QWn5iBNLnVmkL2qOPtaxYtqGvSEem0T3MEcOz6fGYm3J1a j8TwfkNSHTqk2CakR5BUXmZNkgo8kgdGJo4IjdtoiR5X4echn7KMyBOZqcCY/LOuNgCs 5OjPBzto4lNmPGOJ95kk/+Z6YZOMe0GP5iN6DTT3QtvSu1eRvSnqGH1ol0KO66TKBFQy ew5Ao8MZ9aGyTP4VvvkSi3CM0VLPWIWgyIRCbNojOnGW5nE1duKBbUzbQdwHveRHrkgU 72sQ== X-Gm-Message-State: ANoB5pnnqrB7HoUKzKfcGgo4CAWHk88/Gn9s1TlUrcqxZFdDLqmzsfnP s4VN3ixnTgH+KlyueGuMcSA2L4aWsmklGw== X-Google-Smtp-Source: AA0mqf41K5vmq3rhuByfU4W/AtqvhvmmSD+ilGqHI9sbx2YLgKgUB/+/zYf/bq4bL7Zu31IA6ToFXW/4h0yGow== X-Received: from xllamas.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5070]) (user=cmllamas job=sendgmr) by 2002:aa7:83d3:0:b0:56e:8477:1add with SMTP id j19-20020aa783d3000000b0056e84771addmr19165796pfn.13.1669226904028; Wed, 23 Nov 2022 10:08:24 -0800 (PST) Date: Wed, 23 Nov 2022 18:08:09 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221123180809.1501779-1-cmllamas@google.com> Subject: [PATCH 6.0] binder: validate alloc->mm in ->mmap() handler From: Carlos Llamas To: Greg Kroah-Hartman , "=?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , "Liam R. Howlett" Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, Jann Horn , stable@vger.kernel.org, Todd Kjos Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" commit 3ce00bb7e91cf57d723905371507af57182c37ef upstream. Since commit 1da52815d5f1 ("binder: fix alloc->vma_vm_mm null-ptr dereference") binder caches a pointer to the current->mm during open(). This fixes a null-ptr dereference reported by syzkaller. Unfortunately, it also opens the door for a process to update its mm after the open(), (e.g. via execve) making the cached alloc->mm pointer invalid. Things get worse when the process continues to mmap() a vma. From this point forward, binder will attempt to find this vma using an obsolete alloc->mm reference. Such as in binder_update_page_range(), where the wrong vma is obtained via vma_lookup(), yet binder proceeds to happily insert new pages into it. To avoid this issue fail the ->mmap() callback if we detect a mismatch between the vma->vm_mm and the original alloc->mm pointer. This prevents alloc->vm_addr from getting set, so that any subsequent vma_lookup() calls fail as expected. Fixes: 1da52815d5f1 ("binder: fix alloc->vma_vm_mm null-ptr dereference") Reported-by: Jann Horn Cc: # 5.15+ Signed-off-by: Carlos Llamas Acked-by: Todd Kjos Link: https://lore.kernel.org/r/20221104231235.348958-1-cmllamas@google.com Signed-off-by: Greg Kroah-Hartman [cmllamas: renamed alloc->mm since missing e66b77e50522] Signed-off-by: Carlos Llamas --- drivers/android/binder_alloc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 9b1778c00610..64999777e0bf 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -760,6 +760,12 @@ int binder_alloc_mmap_handler(struct binder_alloc *all= oc, const char *failure_string; struct binder_buffer *buffer; =20 + if (unlikely(vma->vm_mm !=3D alloc->vma_vm_mm)) { + ret =3D -EINVAL; + failure_string =3D "invalid vma->vm_mm"; + goto err_invalid_mm; + } + mutex_lock(&binder_alloc_mmap_lock); if (alloc->buffer_size) { ret =3D -EBUSY; @@ -806,6 +812,7 @@ int binder_alloc_mmap_handler(struct binder_alloc *allo= c, alloc->buffer_size =3D 0; err_already_mapped: mutex_unlock(&binder_alloc_mmap_lock); +err_invalid_mm: binder_alloc_debug(BINDER_DEBUG_USER_ERROR, "%s: %d %lx-%lx %s failed %d\n", __func__, alloc->pid, vma->vm_start, vma->vm_end, --=20 2.38.1.584.g0f3c55d4c2-goog