Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp623979pxa; Tue, 4 Aug 2020 13:52:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+owU8bg0oHUUXwJIsgKvsAh913swidtBxRsWz70qOtvp3b2LUR4ULa31Qupr3gmwq+fXl X-Received: by 2002:a50:bf07:: with SMTP id f7mr22786914edk.356.1596574346709; Tue, 04 Aug 2020 13:52:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596574346; cv=none; d=google.com; s=arc-20160816; b=ZLVylAIB7lm+hKgEQ4vJNQpHuLzRly/R/AStfdOvVvRiomn93oEFk2J7xGIOu48liY LgNKDuc/4lzKU5LDt1WMEtHnKjQ5l38c8WpNzlNejgKlyPwytclYhbmSO43PWCJCP2KV yFgb5/3ZuXIvXSNKmY3ev4oXpEZpJIaOTGFL2oxKjYlzqh9Vn+GkS1mYrQmrGwELJhWf JSYxt8ZZpSzAObL2ZlkZ1MWV1rYWIUnuc9wQekkiKXH3Lo80yuQyc+Z2fhTNxu8jyn1Z eaXzTF58FN3A2IFwyZ35/JAl63wJaaZBuTGOk0w0QoM3b9P1TIjR9p5DCFirf6ALzNDI R+oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=hdbBe3yRhb8UVEdZu437BXB7eaBvTiKuwEkcBB5Ach8=; b=0xmDFOodeBnD23rCXlo5HICFxqBw2KixFiiPoWxlUeb2bq+bWa5Pm6gasNweH1TYY1 pB3RSBVNNu9ZmMPJevEgUdYSjzOXiSrxzNi7GPpA7Ay4y1uzw/fkMizrgDDhxX1PZP7R LI4tEJy0oKZE7e+8zyvvL/peqFvVH6Y201EhGrsPUijRQ3Fj2g2lwReyZzat262MpgTu TIY7KSs9Ll+5wMr5mZ7Llr7ziPnuguiVMAQ4O6LvOswEfBrXvp5QhqlIo8XGiEONOLYE ZqzM3k1YjaA4B6ke1hs1rsCTa9jefb3c/t4Re4M3ytktt1WxTH9nv2SBuOoVk0c85tUD nhaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lFjcXr9F; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p22si12105761ejz.561.2020.08.04.13.52.03; Tue, 04 Aug 2020 13:52:26 -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=@google.com header.s=20161025 header.b=lFjcXr9F; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727908AbgHDUtn (ORCPT + 99 others); Tue, 4 Aug 2020 16:49:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727057AbgHDUtm (ORCPT ); Tue, 4 Aug 2020 16:49:42 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29334C06174A for ; Tue, 4 Aug 2020 13:49:42 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id a5so28418916ioa.13 for ; Tue, 04 Aug 2020 13:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hdbBe3yRhb8UVEdZu437BXB7eaBvTiKuwEkcBB5Ach8=; b=lFjcXr9F4a+6cunETjp4ZXM/I9v82oAd3si1GWvBuQeX12mzbQTmu0WziwTImnxUZX D5FYlTosNhLxTjnxBTuvFt9IreQCsWSGZW/ZuU0o7Am1OZzI6OC+SuLZF7YUaZ60OnzX JIcxq5mu09QLmMwHGcBZrtkA7xMR7O8FTwnhdyNHCFWK2nuqZwothaNVoJwk1Gqknzuz iH8QY2MHTTsGmp+za5ED2Cp//msh+V/NPXqq9bs8NkcimZxEj7NgYNUXqZoUtTJHVmCt 5SLr2qVrm7X3f4UWMMJF99H4Mdbk9SkX+eHzDma1G0+g8hygOADVDxbGdLvBD1hprHoo qskQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hdbBe3yRhb8UVEdZu437BXB7eaBvTiKuwEkcBB5Ach8=; b=C7kFVjsPKa/hTqzusCoCzaTYb3/0/94SgGc1m4y5tvg8Mfx3j8pX6MCjKdJuAohLpk ZnZ0IeEauh5ICnWsE8IvLWJ8yIERWaT2A8N4Dn99DVPWBSB3R5JDsr153catvGMZIhZj 3lUOQinnVmdTzbDn2+FHHH017L5jxE1T0wjcpHfbDiVavJO1c73fbRIyOJhXrsPwnW93 vbmrJYVHehpOBTC/4g62zeHJIX29EFap6xDNpPYvo8/s6fhChPI1fT+98YkYZ2AISDLr ZvaY5uf55qj4IltqV/4pNmn9nXvJBNvK9IvmmUNwMiu8b7+h/iF+4gndjZDCga6bEz6A uHSw== X-Gm-Message-State: AOAM531vClDv2DOO9Ge1g6pYMlveYz4Ql9nYjtPOKMznKSFj8EkXjDmI kiz3UX+BxBxTZFzSpqoEpAEFU2j1GTluXaWx/j2Gqw== X-Received: by 2002:a02:3843:: with SMTP id v3mr32714jae.23.1596574181355; Tue, 04 Aug 2020 13:49:41 -0700 (PDT) MIME-Version: 1.0 References: <20200804203155.2181099-1-lokeshgidra@google.com> <20200804204543.GA1992048@gmail.com> In-Reply-To: <20200804204543.GA1992048@gmail.com> From: Lokesh Gidra Date: Tue, 4 Aug 2020 13:49:30 -0700 Message-ID: Subject: Re: [PATCH] Userfaultfd: Avoid double free of userfault_ctx and remove O_CLOEXEC To: Eric Biggers Cc: Alexander Viro , Stephen Smalley , casey@schaufler-ca.com, James Morris , Kalesh Singh , Daniel Colascione , Suren Baghdasaryan , Linux FS Devel , linux-kernel , Nick Kralevich , Jeffrey Vander Stoep , Calin Juravle , kernel-team@android.com, yanfei.xu@windriver.com, syzbot+75867c44841cb6373570@syzkaller.appspotmail.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 4, 2020 at 1:45 PM Eric Biggers wrote: > > On Tue, Aug 04, 2020 at 01:31:55PM -0700, Lokesh Gidra wrote: > > when get_unused_fd_flags returns error, ctx will be freed by > > userfaultfd's release function, which is indirectly called by fput(). > > Also, if anon_inode_getfile_secure() returns an error, then > > userfaultfd_ctx_put() is called, which calls mmdrop() and frees ctx. > > > > Also, the O_CLOEXEC was inadvertently added to the call to > > get_unused_fd_flags() [1]. > > > > Adding Al Viro's suggested-by, based on [2]. > > > > [1] https://lore.kernel.org/lkml/1f69c0ab-5791-974f-8bc0-3997ab1d61ea@dancol.org/ > > [2] https://lore.kernel.org/lkml/20200719165746.GJ2786714@ZenIV.linux.org.uk/ > > > > Fixes: d08ac70b1e0d (Wire UFFD up to SELinux) > > Suggested-by: Al Viro > > Reported-by: syzbot+75867c44841cb6373570@syzkaller.appspotmail.com > > Signed-off-by: Lokesh Gidra > > What branch does this patch apply to? Neither mainline nor linux-next works. > On James Morris' tree (secure_uffd_v5.9 branch). > - Eric