Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp88827lqh; Fri, 3 May 2024 14:26:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWKf8za11yPSCKn6pGsvLppXPeJsf2Phd163/7bn/LoaICRkD2yZ3suB2jTxr6/YQHkHcf4SILCU2rM3Hrj0RZjf4zQiXtiScP4HF+JCQ== X-Google-Smtp-Source: AGHT+IELsBUEQPweBHNiqXlkbxa0E2LiaQMuDENA2nWd61mAveGDA9osH4GxZGxeh6afRkQ23Jmk X-Received: by 2002:a05:6e02:1c08:b0:36b:3b2a:39ce with SMTP id l8-20020a056e021c0800b0036b3b2a39cemr4923455ilh.14.1714771604145; Fri, 03 May 2024 14:26:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714771604; cv=pass; d=google.com; s=arc-20160816; b=flJeNb4wyrP15XGVUvp7PbUJIzH2yhzk3Uc7HoFtQjYk5h6ctYVMp+1s9my4SB/+Ni 0uiXkl4tdKUkaAQJbtfx2ejeKqMm6YTFrEpSk+d4cwxyiZOYE+z/YPUbKwkUxVsEEZCQ ul7rNwII413aSnoCw1ZIGJvrKmuFzeGaUyJdhX4sY/eGuMKQ06DS1pgm9tKMZwJ0jV3/ VPoNWtj+scgD8s5lDRMVyIsyiSNxfTseedQ1QDExUY45ChroLeO/mOuPIYzrFayu7bnm FI9+HDJdiCIvmYooGT1S1fxt3MMDQR9tJ6aeCfdtMjweyTO6ZGW1RdVEqYVMboWsaAEB 8bkQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=fhxz4aHpmXZJ6K0C5hNTESMtOJDx3oTLGnKkbndye9Q=; fh=57SVujuutJp0ONJWd4qY3AWf6JlqvyYlU3uGNnzyKoo=; b=VkZ/9o/QSdTnU3lO0XZbUGH6w7XhGcZTC6Vq4OASDwf63bNTnzCGpAbK8oh41iMcrB rzvdI76OClvIJ35axaIPLYspkqdjnzoH3Sflj6iA1HZyddcVRZTCBr/SVHKMYfZK/n2T OeMlYJXDOy9EFcjpT8R5z8qn3BDj4uJ6mH0NjZbb4r/JaKXrWqXdtoQKqMLeJq2D9++T xvC+o8Unt9/upcCPLr0M1C1+vRu5mOr9JUSrqlTRtyZBm24bRxbPNHhsmn0UjrJsJuC0 esFS/S1dlqgHY/y4wB5pGtk2uvcwbZji/IrIgod1ni5fYdsuEH42Je+26cTQt/WwVi6D O9pg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=S0vunfap; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-168250-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168250-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w22-20020a63c116000000b0061b187f3e3csi3027513pgf.183.2024.05.03.14.26.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 14:26:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168250-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=S0vunfap; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-168250-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168250-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C2B8B286575 for ; Fri, 3 May 2024 21:26:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1074E5BAC1; Fri, 3 May 2024 21:25:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="S0vunfap" Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CA915915C for ; Fri, 3 May 2024 21:25:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714771507; cv=none; b=YGaRT/sxIDkmECuVpIyBCLtanWNwjlqB7HzlYBemzSBpgmUAiHloL/Z8MySVO/GAYeir1mpSRSJeBGrT6NTFS8eennxCo/+U2NJqSeaWU/azGO0Yp11um3uQpOaIk4P5ZO1z24ggcudSBVMfTHWfq5uzh/hoyx/anfRIjOOtNwU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714771507; c=relaxed/simple; bh=N4MV6W6kLCjF7hioiCGBWf5TZPj+wehXzH5NmRppkU8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=T/JMlZvekX8d/D57U+jKkFFLOUcTwRHZtVK/cl38dfSRe6RMJJT7D9/i20Ty+I2EDWZ4891iJ4P5NeIBej/IidbwSvtB8kdlu9DnCIPzCG8HpKr9m2l2XcOSK89iUYCQpBhzMT3OMqrBqSCRqS4d0DlCxogDmuIvPC6wM4e3PvQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=S0vunfap; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-51f300b318cso79000e87.3 for ; Fri, 03 May 2024 14:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1714771503; x=1715376303; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=fhxz4aHpmXZJ6K0C5hNTESMtOJDx3oTLGnKkbndye9Q=; b=S0vunfapGZrfyWb8cs4gm4MDwD5hFZLlWm10XHyrLw9LIYzuUzQEcfmetydymLFBVC q/dYgQHGwDlmzjZdANFqhKvfChtpO3DCNmVxwsq5qRXvAEysz7yJPRT4LoDLUd+w6d4J gMS/QtZ6XqzGRjBYPuIDsMGbMqkSS2UL6WhFw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714771503; x=1715376303; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fhxz4aHpmXZJ6K0C5hNTESMtOJDx3oTLGnKkbndye9Q=; b=w6K9i3g/p/rPv3Aoo4d3QZNDOl9V5E6bGul/IVyS54i3p1oazhQ0n6j7IEOBlJM77b wbFmPxlsFLWtvgIerGF7NGC3ujRnpSIvVLlJ2YcUS17XQWj1ehmAQ6CNm/HNfwJWnvmT wI0BInxgs+pzjYs2F9cYUyDg7EodDq5NnyDZIChAYx42DQBIAsX6NVtv6YU3HZOQ6G19 G/QG20EpocgxDoNrQUP4qhR0IgItIwwD0zoHTd2GfTifVMe7BDm9RlMYvpTSUxzQg/mJ UURqE9jTa78Ox36Qiv95pkvmph8zw8Cn/jSnZXPax2DqmgdrdNpa+RlTIplZx1WXHQsS WTKQ== X-Forwarded-Encrypted: i=1; AJvYcCXzWyuoibLX0iePBO34Eoo69ZK4l8fvvFrl7rXwWCV4Crh3Ac5X927E0LMmKtunjVkV4uwM49hpRJrnHUhJof+0tyzX2XrqyUVdykrP X-Gm-Message-State: AOJu0Ywff63NHjhzSP6k1ztj3VnFHVbIk/STARlTxQDDXTYBJF6ED5rL 4epO317bQDBoBcwMjkIG03JezMFnodn19pBbuby14DmAKIPP69omMr0g1f6iULX9n7j5F8GOryn fRPiynA== X-Received: by 2002:a05:6512:4898:b0:51f:6223:2205 with SMTP id eq24-20020a056512489800b0051f62232205mr2541988lfb.44.1714771503233; Fri, 03 May 2024 14:25:03 -0700 (PDT) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com. [209.85.208.182]) by smtp.gmail.com with ESMTPSA id g4-20020a056512118400b00516dc765e00sm653754lfr.7.2024.05.03.14.25.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 May 2024 14:25:02 -0700 (PDT) Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2d8b2389e73so1256141fa.3 for ; Fri, 03 May 2024 14:25:02 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCV9uU42OutnuQMXoAAOdor6gsOswV41rQewVI3u1iO26KcXSVoaV+q3k0VJhksaa5X/hJRBwu/L4uVs1FS63xuTmS51Q2xYwf4BgxGi X-Received: by 2002:a19:381a:0:b0:51c:68a3:6f8e with SMTP id f26-20020a19381a000000b0051c68a36f8emr2449065lfa.31.1714771502428; Fri, 03 May 2024 14:25:02 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <0000000000002d631f0615918f1e@google.com> <7c41cf3c-2a71-4dbb-8f34-0337890906fc@gmail.com> <202405031110.6F47982593@keescook> <64b51cc5-9f5b-4160-83f2-6d62175418a2@kernel.dk> <202405031207.9D62DA4973@keescook> <202405031237.B6B8379@keescook> <202405031325.B8979870B@keescook> <20240503211109.GX2118490@ZenIV> In-Reply-To: <20240503211109.GX2118490@ZenIV> From: Linus Torvalds Date: Fri, 3 May 2024 14:24:45 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: get_file() unsafe under epoll (was Re: [syzbot] [fs?] [io-uring?] general protection fault in __ep_remove) To: Al Viro Cc: Kees Cook , Jens Axboe , Bui Quang Minh , Christian Brauner , syzbot , io-uring@vger.kernel.org, jack@suse.cz, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Laura Abbott Content-Type: text/plain; charset="UTF-8" On Fri, 3 May 2024 at 14:11, Al Viro wrote: > > What we need is > * promise that ep_item_poll() won't happen after eventpoll_release_file(). > AFAICS, we do have that. > * ->poll() not playing silly buggers. No. That is not enough at all. Because even with perfectly normal "->poll()", and even with the ep_item_poll() happening *before* eventpoll_release_file(), you have this trivial race: ep_item_poll() ->poll() and *between* those two operations, another CPU does "close()", and that causes eventpoll_release_file() to be called, and now f_count goes down to zero while ->poll() is running. So you do need to increment the file count around the ->poll() call, I feel. Or, alternatively, you'd need to serialize with eventpoll_release_file(), but that would need to be some sleeping lock held over the ->poll() call. > As it is, dma_buf ->poll() is very suspicious regardless of that > mess - it can grab reference to file for unspecified interval. I think that's actually much preferable to what epoll does, which is to keep using files without having reference counts to them (and then relying on magically not racing with eventpoll_release_file(). Linus