Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1911003ybh; Fri, 17 Jul 2020 04:46:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVCXvjy/DeS4GoiVpZq2eYokvBadrUU50cw7D91aqCXxwIaZOeMs6B1ftdVXqSwaNJc0qx X-Received: by 2002:a17:906:270d:: with SMTP id z13mr8010299ejc.281.1594986392098; Fri, 17 Jul 2020 04:46:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594986392; cv=none; d=google.com; s=arc-20160816; b=MYkKXJmyVumIdkBHdj2fH99K5YgJiWXbQB0EUznKLSgWyM55Jh5S2Ir1pmiq3rRuHu IagigDzjHecXpBZZAwN6ZA5yWpy/zmiYOzoVM6LDkZbx59Vtrtnsl3EqiLE+25+sLFKy txCaqLmf2TW0Wxjzec6ylefdsyoqg/v8axp2PS6Pi0llCjRh6C+JynYqW+QCMgn2kTsD gk4nKPcDzvyeim1B6XsMy3ldjnhxTGreWvCi9fundPGVBRiX6E7Dhql2EdXIOkiuozgJ 4/CbuagnNa57Gz7mbJlcjuD/OVkaoIpRQo/KJxzwEMEk4Tp52T/eHorw7pyxYNRqtBe7 05SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version:reply-to :message-id:subject:cc:to:from:date:dkim-signature; bh=RGmCnCujTCPHPAqseUf5nHct0c3cR5+Pl0sn8j65GRA=; b=rF02sDFBEIIAuddSnMb35k7ij9DhQq0wScoJ8ZnI93L126ED35Fwww8kDQAg2vipnj j1mE6gFy00NNopv73BC+6Fb522s45piRnCIk3m0ppbatwvBQG5VBugBiGRZwl7yPHJar NBxWHrkLd9hQYr9G0289Nb/xW1xB1AVSeuG3mAhEWKLW58TNXY5wzJu0r6F2HchIK9AN mrJ+AJI8r/g5KO61oyKMYAh8+/ZCwJx9srWG1zBWAxbfqfJ5gSj7vNvT2H5bND9b6KEc LH2wDTvhl0f0rBf3qqCPlj3j6BL//9JPrIZWvfDtmpnM0DDOL7lAgYDUhFAB7qJvb4+W i+zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=La4PoFUS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b30si5081555edj.204.2020.07.17.04.46.09; Fri, 17 Jul 2020 04:46:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=La4PoFUS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726892AbgGQLpi (ORCPT + 99 others); Fri, 17 Jul 2020 07:45:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbgGQLph (ORCPT ); Fri, 17 Jul 2020 07:45:37 -0400 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44939C061755; Fri, 17 Jul 2020 04:45:37 -0700 (PDT) Received: by mail-qv1-xf41.google.com with SMTP id ed14so4095569qvb.2; Fri, 17 Jul 2020 04:45:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:reply-to:mime-version :content-disposition; bh=RGmCnCujTCPHPAqseUf5nHct0c3cR5+Pl0sn8j65GRA=; b=La4PoFUSodowSJLHupAbyoCryYe4IscT0uVjcLdnBdcKu34q4TNYPqzS0Nr/jQc+EM F2XyfYyxL8FQhKctiFagZGB9yxdA12JMq8JEvISZeKuMS1vZ5/Oau3CFZLgR8K43xiUU E86yO3eN5U8q9hW+83UrqolEyLOq60sn5RWpuN0fRb6KFwI9m265IqtAwKVQfl4cygy3 0jKEYBIANHgXGZAdahfISR5yQA6FuB5q/EXPJLjCM6LtRPdNK0IPKb1/gbZHs22PgaEY wX7lul5113brAi0ptNWB69Sc4TE4p22uWbGzG5GisCJcFbMfc7QZcO5iTG1ztdjRVt0Y Uktg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:reply-to :mime-version:content-disposition; bh=RGmCnCujTCPHPAqseUf5nHct0c3cR5+Pl0sn8j65GRA=; b=qGMcyCf5HiazK1TIB0hEeejdA3gHvOawaLPnyms2I80MHbS8qx+o82rYiqdlXZqGh9 uQ5m45QAM8osavfd8fGRENDtx5tn/ZC+BQnWASw5CozGSRLCv3P1BKgxernNSPlQG9t9 yNmzTbUayGQqaOXmynwmmr5iiTyctbQMfboKgsKnnHRvV+lHE+s82oxgRpWQRVtzPLac 3HFO243rZmJKbIS/t+Xwtf4YQuHe4MvutB4I+Z51/IOetbxdqF2n8fs5zAzNBL7cKrf8 yOZ7ZRyScGsqvrb3/NPEtql26mXxDLaTdTfuF+3rHq1g5AJ/xFfK8dMVcQNiN6SA6235 QlEg== X-Gm-Message-State: AOAM531570kqhHP5igGwvvl+K2wnd1utHryrtT/hwfmxrojj0j/iwn7n kCwVuEussoQoreJ4MQ/jPMSPFLuE0k3W X-Received: by 2002:a0c:a992:: with SMTP id a18mr8145355qvb.211.1594986336193; Fri, 17 Jul 2020 04:45:36 -0700 (PDT) Received: from PWN (c-76-119-149-155.hsd1.ma.comcast.net. [76.119.149.155]) by smtp.gmail.com with ESMTPSA id s8sm10967968qtc.17.2020.07.17.04.45.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2020 04:45:35 -0700 (PDT) Date: Fri, 17 Jul 2020 07:45:32 -0400 From: Peilin Ye To: Daniel Colascione Cc: timmurray@google.com, selinux@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, viro@zeniv.linux.org.uk, paul@paul-moore.com, nnk@google.com, sds@tycho.nsa.gov, lokeshgidra@google.com, jmorris@namei.org Subject: Reporting a use-after-free read bug in userfaultfd_release() Message-ID: <20200717114532.GA688728@PWN> Reply-To: 20200401213903.182112-4-dancol@google.com MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, Syzbot reported the following use-after-free bug in userfaultfd_release(): https://syzkaller.appspot.com/bug?id=4b9e5aea757b678d9939c364e50212354a3480a6 It seems to be caused by this patch. I took a look at the stack trace. In the patch: fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC); if (fd < 0) { fput(file); goto out; } If get_unused_fd_flags() fails, `ctx` is freed. Later however, before returning back to userland, userfaultfd_release() is called and tries to use `ctx` again, causing a use-after-free bug. The syzbot reproducer does a setrlimit() then a userfaultfd(). The former sets a hard limit on number of open files to zero, which causes get_unused_fd_flags() to fail. Thank you, Peilin Ye