From patchwork Tue Feb 15 20:19:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 12747609 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48819C433EF for ; Tue, 15 Feb 2022 20:19:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B9A6B6B0078; Tue, 15 Feb 2022 15:19:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B22E86B007B; Tue, 15 Feb 2022 15:19:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C38C6B007D; Tue, 15 Feb 2022 15:19:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0039.hostedemail.com [216.40.44.39]) by kanga.kvack.org (Postfix) with ESMTP id 89CB96B0078 for ; Tue, 15 Feb 2022 15:19:27 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4611795262 for ; Tue, 15 Feb 2022 20:19:27 +0000 (UTC) X-FDA: 79146129174.19.C5D3E83 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf04.hostedemail.com (Postfix) with ESMTP id CDB2540006 for ; Tue, 15 Feb 2022 20:19:26 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id s133-20020a252c8b000000b0062112290d0bso28101934ybs.23 for ; Tue, 15 Feb 2022 12:19:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=3sykFJBU7TaEMZYTogVM89EYoDudBlD4QLkfsqx2ZFE=; b=QEf2mqWTjsa/E5krOX9OFf7ks4YOwL85No0GxFrV+2PebGS/cgnPqjSnvDvOSc3RvM Trxc/NaUhms8VlGKEMxWAPncnpKWXBwNLkT8jjzFbxCLXyy/RnVm2l4E4ZGu+ok0bYro KBvBrkBDZrFzWqXydq7l3gbslupJKMpdQtBTdrSzRNYfM5qOXDKhJOlSi6/37uaWqF8t TQg33AD3bLwrpN47rtY84vbuKcqHJuPVlxINx7v8M3wdXn7Vkd/yyAfLBAWG57zXkUJx z5OQ40GXQjt5ZS++yzyNLCiJFClwSux7MndH0Kvc1Ehwg7eEMR7dzBqbTgURQ84WsJwF 0MFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=3sykFJBU7TaEMZYTogVM89EYoDudBlD4QLkfsqx2ZFE=; b=sWpnTDyGRXxUBIyUJDCfeF+OefSTBGTxQ3L9w93BtZvLEF9Cl6nU9DGLuXjivCqWJI jFL3H6ebLAwZO3EQUGrqwyrhReRRpnjm6jZ1sRUEc4grFW8C8R8Af9za0OAB4VpECeFk 1i0kDJ1gU387Z6CYKs6dR/crWzZgYjXIBcwxfdlvRybc15PyjdLnz10ikfAoq0Pt5c3s nFlzlw8hfsxzJUuZWRb6bRrWLNRKP9kNzblIZ7OLYuAu/dTOx1fPsRgLHV7ADcPVXB4T WkvCVEH4YVjXQbMqsbN955tc5mG+lw3rLaBMWyQTvkqyTU9U1x/Pnlex4+xCqeOAteRk 54nA== X-Gm-Message-State: AOAM530G9xFz11I25zwbCxE1UJEtoItP3SDF6qPURMqbhoL6Vg8iMDu1 UBxeVJE7gh4sr4nXrK4+Pfo2y45kVi8= X-Google-Smtp-Source: ABdhPJw4G1dyLTGbU/4oGbsYbMXCg+jUT4P0G7PyusNh5KoZcthlKjSwWZ7ONGwtSRvNQbayc9fkxTBjGfQ= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:c779:6798:9711:86f4]) (user=surenb job=sendgmr) by 2002:a25:dc02:: with SMTP id y2mr631611ybe.0.1644956366028; Tue, 15 Feb 2022 12:19:26 -0800 (PST) Date: Tue, 15 Feb 2022 12:19:22 -0800 Message-Id: <20220215201922.1908156-1-surenb@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog Subject: [PATCH 1/1] mm: fix use-after-free bug when mm->mmap is reused after being freed From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: mhocko@kernel.org, mhocko@suse.com, shy828301@gmail.com, rientjes@google.com, willy@infradead.org, hannes@cmpxchg.org, guro@fb.com, riel@surriel.com, minchan@kernel.org, kirill@shutemov.name, aarcange@redhat.com, brauner@kernel.org, christian@brauner.io, hch@infradead.org, oleg@redhat.com, david@redhat.com, jannh@google.com, shakeelb@google.com, luto@kernel.org, christian.brauner@ubuntu.com, fweimer@redhat.com, jengelh@inai.de, timmurray@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com, syzbot+2ccf63a4bd07cf39cab0@syzkaller.appspotmail.com Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=QEf2mqWT; spf=pass (imf04.hostedemail.com: domain of 3zgoMYgYKCCsZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3zgoMYgYKCCsZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam07 X-Rspam-User: X-Rspamd-Queue-Id: CDB2540006 X-Stat-Signature: 4bxnx8msb8zkm3rpzofchi41hau85byn X-HE-Tag: 1644956366-301920 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: After exit_mmap frees all vmas in the mm, mm->mmap needs to be reset, otherwise it points to a vma that was freed and when reused leads to a use-after-free bug. Reported-by: syzbot+2ccf63a4bd07cf39cab0@syzkaller.appspotmail.com Suggested-by: Michal Hocko Signed-off-by: Suren Baghdasaryan Reviewed-by: Rik van Riel Acked-by: Michal Hocko Signed-off-by: Suren Baghdasaryan Reported-by: syzbot+2ccf63a4bd07cf39cab0@syzkaller.appspotmail.com Reviewed-by: Rik van Riel Reviewed-by: Yang Shi Acked-by: Michal Hocko Signed-off-by: Andrew Morton --- mm/mmap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/mmap.c b/mm/mmap.c index 1e8fdb0b51ed..d445c1b9d606 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3186,6 +3186,7 @@ void exit_mmap(struct mm_struct *mm) vma = remove_vma(vma); cond_resched(); } + mm->mmap = NULL; mmap_write_unlock(mm); vm_unacct_memory(nr_accounted); }