From mboxrd@z Thu Jan 1 00:00:00 1970 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D779BC4345F for ; Fri, 3 May 2024 20:28:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 092A8112991; Fri, 3 May 2024 20:28:40 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Dx7QLm68"; dkim-atps=neutral Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6554B112991 for ; Fri, 3 May 2024 20:28:39 +0000 (UTC) Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-5ac90ad396dso47942eaf.3 for ; Fri, 03 May 2024 13:28:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714768118; x=1715372918; darn=lists.freedesktop.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=Dx7QLm68T/oXq25LWGJgbIwQcbAjDDeWpHkxKElz6MrqHgr8QxlvF3UcMcDgX1TrO1 u3B5TkmvLTRvEdFv+mqbSWyWn2YfZDi8GcZ6k45/6vERlT423B71wphIcURL9V7yTjoj 2irwhxYJeewwba9sWSwGzH9hC1JLP4mmSIGaA= 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=S2rqZwap58wVGejJym5DprEX47ZWdxAIbTNgwB5ltqQXbQIZwqq7O0RMnyFDAYA/U0 S7hO+VyrrzXTHbR7kaq2bSFK8mtjIzgqFd64ZRKsfBjKDyhnZ/xe3Sds1j7QH9HrdmCz fao56t0E5SC2kAI6kVVqn7Yu3TJ/Ph+J4I3Je+csr60Tv7RBiHNJ9oNzZTMzKQZ/glpD KDKNLGdNLzmSoZGzcNSb8DP04bZT+Qi8H5/LAw1myaudpe/0vDxkIucnFRKaSPFdLB3k sOFGyJBWw8PzJhGJnj1b6pLDU4HOR7pL8EE9nEDUF4Xb3jXOaO560//Wzfnk+MDutb8p 3Plw== X-Forwarded-Encrypted: i=1; AJvYcCWELd7xnSw0NMgGafs7aB8O+ZmvAfdmST8GK5UFe7jUcl9A6jdKgieA28pcD46wKJBAfQHlu0m41ilZGjX1HcEhgyN7HOUmbaw7QPXhPB1z X-Gm-Message-State: AOJu0Yy4H+p3OeV4okyh0CxK+AVrD8mNg0YST5Zcc2Q/PakEvdWz7Ed5 2kBV+kEmlVDo9AmdDq5viTDZZop29qup8/fQRmuBunq94hBAtXc1RVU+qFMRTX1tKmsE7nzpUt4 = X-Google-Smtp-Source: AGHT+IF94HWVpg+ieTREfKNo4EYCAREwn5FJES4sWZrWNDrTepMs4qAK9EBYEOGD6R0pN+rBpz049w== 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202405031237.B6B8379@keescook> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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