Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp63102lqh; Fri, 3 May 2024 13:28:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUUPZxyLljs5ndl9A0JrIrMw7a5PBfgn9RX9bINz/KChcQDLKLzewsyhu8tdNDvVZi4xsPh4e5fnPH/mjtTrnWKENcC35sOKN4t4Fe3PQ== X-Google-Smtp-Source: AGHT+IEUy+nMUqrDeNfAubw1WUGEkrGYVctYfWa8C93NEMVyYkHt9CFyjBYfLwR1nlfj2oZlK2NX X-Received: by 2002:a05:600c:1396:b0:41b:aa11:29b3 with SMTP id u22-20020a05600c139600b0041baa1129b3mr3015164wmf.35.1714768133678; Fri, 03 May 2024 13:28:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714768133; cv=pass; d=google.com; s=arc-20160816; b=MZhct2OFxrZoEneZZT4IcaXHYvV2UJyzl/LpuFYQohUF61rKPxZqf8+EROuoXigBMy n19RturrpfaMZD6o9K3TIxqYpkozEyNpc8WW67NBoGNASoQsTFpXuyoHUw+xQPmL72tI pSV/bSfKUjLJIc3R95B7SnLLua1CygDLDdPhxq7Sg45ThKJeIIi6We2hP1zUJZURsAw9 D7IU6zPs6cT5aMuI6WW7H5NrIXP8OjV/wAPFdtH2fxJcQ5FAMc0LNKPzotB/rHcF+L9f LCt20qL7z9DdJ7yXFkSW4hUTxwgNFvubDOU+QI7gQJJ4RKhn7WRX6O1Ajba4x7xKECSz bhYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=1iqzX4jEVf88YLxrEdDnezO793F37cz7yvxwfuzhVk4=; fh=SJ72daOOPEGYopCVPcQr9zlva1QKS+aKD2Oos912arQ=; b=QZCiJOUX+0iohpZb80kV+tFmzcK5nz/kNq79TEm6xBPXQd2dh6sftHZEOsfrC7pvdE K/pTcW8rH6Af8YEpLU/GbRkpeyE8T6bxA6CQ4g7yavRtYHlAPRlmHbbgM0PEqUaw6BeM tJTnw5lmD8c8TISo7l1fGsxz/TVtRExreV61M302fFnOPSzMgJBOJXRqm/QccJq7IFeX 8AdEfELep6zt4GWc7uckFiVMFilX5DO3txIZGE9/Om3xIdlowF3aPiFIsnTQo9qAEwUI mV6/xoakvm6InVrDyLgaIACoiM3NGtHoSuwwvH3ldxDVeN8CTil65Akax7fDuv2cGU/a mYEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MFl3aMru; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-168180-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168180-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x9-20020a1709065ac900b00a59a00da1a8si322698ejs.715.2024.05.03.13.28.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 13:28:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168180-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MFl3aMru; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-168180-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168180-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 618331F232FD for ; Fri, 3 May 2024 20:28:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5246F158DC9; Fri, 3 May 2024 20:28:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="MFl3aMru" Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) (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 1A49112EBFB for ; Fri, 3 May 2024 20:28:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714768121; cv=none; b=M+goQF5YTOtV+b33qmkJpah3t9nGF7qWrSX5yfABsFkuxTE9v5LOo/QuBYtFxWW7ZmNErUBqjTbi7+5RszuvO4vndP68cCWGHbQQ227Ua8exFVRNlEOyNCFgjgzWWexG8uXmdz65vlbnnfZ2ZsdrjPj2b3f0sUR7xrGk5CPflck= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714768121; c=relaxed/simple; bh=uqcs2WtkKRadbRkgGXZX4d/MnzZr9F+VgkdeEm57dwE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=llDTYeS8GYa1gXDQshEvI2oOBOTtEcx6vVwxeVAumEDuh+JUV/u9vSSWCc3244iw2OqC+HKGlY78h2xfB+vIrBSDaZvX41CScF+iG1xee3MBZP95IOcPT6bdWoAnSM09tsGebcOp1PJ4u6BRQC2/Bn7ej368zoEo16Ghrl0O9gc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=MFl3aMru; arc=none smtp.client-ip=209.85.161.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-5aa1bf6cb40so72069eaf.1 for ; Fri, 03 May 2024 13:28:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714768118; x=1715372918; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1iqzX4jEVf88YLxrEdDnezO793F37cz7yvxwfuzhVk4=; b=MFl3aMrudLTG6woBI3MzX3NVA8/nIldg9wzSH/6cqQEEiT9oKmFz724DjHNByklU4T lZh3e1uomz0KRqWVMZV2SXDxoi+R3vknpoJzTpuJxdhtZHckBuXtTKAIFNIfi+ZLA7/P yTo7rdM96D2runS5qOEeA82Nx/S70E4J3gUJE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714768118; x=1715372918; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1iqzX4jEVf88YLxrEdDnezO793F37cz7yvxwfuzhVk4=; b=YMMLyC3GTecxtpF8nGin9cSFeXP4DE3RILcaooVvFG2UNAM3gROXFPk4B4F5BfkMtM NZ3rnksUN2TuAlQ0/CpSWc/mohmP+pH4azFT0czd9GV6gBBiU9gX1Dibx2k1N1RUaFJl 1ebTwmEgKcwwt468F/P61EI0JS4vPxMmAAyHWxRQSdsn8UbqHRbXXoBen3kebDKogro2 jcNjRFWi8Pxy1GRtMmlNAIBd9VBEfvU2bClFOoZEdxKdZfdDMUnqhj35SCtuA8kQ4Wbb ZXhRNFhlr5rELPgW3l36EwMMbCl+PUtDGoSIXw5RZOmvPh8sk2QH4Y2iYk7OBTCpWNdk LEeg== X-Forwarded-Encrypted: i=1; AJvYcCV7C6He8HItPvNfEoNMGIFChXCqIuvnzYr52UqgslIrmPhux22EZZoCuh1d6Hq4MHdwvZudFtTl+cFyjiRuOXNxdVs9rFfGQEplTITq X-Gm-Message-State: AOJu0YyTTiQ7kEFHa2VZMIBgK9sGNPa3BUeqePUDfLmY4Xc4tDRN/VP7 atkjs4HXZ2icia9kt2gLy0TzY8lANK26TTl0tMAR7ipqXUKBMUpdY0WKS1T/AQ== X-Received: by 2002:a05:6358:9481:b0:183:645b:cfa4 with SMTP id i1-20020a056358948100b00183645bcfa4mr3887974rwb.16.1714768118230; Fri, 03 May 2024 13:28:38 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id n16-20020a63ee50000000b005f3d54c0a57sm3551694pgk.49.2024.05.03.13.28.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 13:28:37 -0700 (PDT) Date: Fri, 3 May 2024 13:28:37 -0700 From: Kees Cook To: Jens Axboe Cc: Bui Quang Minh , Al Viro , 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 , Christian =?iso-8859-1?Q?K=F6nig?= , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Laura Abbott , Linus Torvalds Subject: Re: get_file() unsafe under epoll (was Re: [syzbot] [fs?] [io-uring?] general protection fault in __ep_remove) Message-ID: <202405031325.B8979870B@keescook> 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202405031237.B6B8379@keescook> On Fri, May 03, 2024 at 12:59:52PM -0700, Kees Cook wrote: > So, yeah, I can't figure out how eventpoll_release() and epoll_wait() > are expected to behave safely for .poll handlers. > > Regardless, for the simple case: it seems like it's just totally illegal > to use get_file() in a poll handler. Is this known/expected? And if so, > how can dmabuf possibly deal with that? Is this the right approach? It still feels to me like get_file() needs to happen much earlier... diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 882b89edc52a..c6c29facf228 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -991,9 +991,13 @@ static __poll_t ep_item_poll(const struct epitem *epi, poll_table *pt, __poll_t res; pt->_key = epi->event.events; - if (!is_file_epoll(file)) - res = vfs_poll(file, pt); - else + if (!is_file_epoll(file)) { + if (atomic_long_inc_not_zero(&file->f_count)) { + res = vfs_poll(file, pt); + fput(file); + } else + res = EPOLLERR; + } else res = __ep_eventpoll_poll(file, pt, depth); return res & epi->event.events; } -- Kees Cook