Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp999141lqh; Sun, 5 May 2024 11:04:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXQtaiOXaFT/EOqanxvTRHZPCO1wCrgoLVXbu3jyG95x4Z4yEqhLMBdLWFDMq4GEQ+1emGvQoDYkjwK5I6OMEnRusy4Dn/4eN1bDhRGNw== X-Google-Smtp-Source: AGHT+IEWtUy/zc7BK21UfWI2wHoMLdyQVnPqJDbeWwMnqqtHhGXnv3F6Qw2xvw26rL8tNbtSaXz/ X-Received: by 2002:a05:622a:450:b0:43a:ffb9:e7e0 with SMTP id o16-20020a05622a045000b0043affb9e7e0mr10109879qtx.38.1714932296973; Sun, 05 May 2024 11:04:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714932296; cv=pass; d=google.com; s=arc-20160816; b=tNWeqHLDavuhPa57nboDj224YBh1km1rPwHlNTzhKxW8PtFL1yW6CstBs8xA+/rwAJ 6bC2liMS1CyAOviIyMyTYAN+Jk2K9q7kuia5mterMU/HALq4I6tU9p4DwZLVnemAHJ44 /T90K8mqyshnymEGi47K9gwOo/2t//oU9U38SEYkjjSH9nLtrR6OQdKdwzhUNYC3Ag9a n2+gmsPK5asOEkqEggHRiTi40/e+7/ZuaXh9bCADRcZdXP/zcS7Nfvz7NoSNFZjiCUT3 L8jvhHtIMDbSNbdrgFqwAx8RUJn63HE4cCVl03qFB416jdfK4aPTfDYDMkHc7A7arye3 eIOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=mE6ET/wemNoj1wnsoN5H46vn2H9jFrdPiFfXm3O1q/E=; fh=Kf4dJxGPhliLfPPEN9mZgzKKr6wIg6fM+k5Jmd8DeTA=; b=Pb0kD3rB54WbovyQCEJuBa0Ev8FPFtZg9svPFj7S6TcsQnGqOmPDp4puzQln6ppjW/ ++kGCCHVlMTT9RhUkWivwYeJQlAqWpD6agoNuDOD40MoIIjZZkV0v3c7j8P+rkOXsIbT HMkUpnaqQEdWs2fOJlxKE7/VK78XP2xmZj6VDenKKbgudo1i7aZlv0lQXU2EFS2Wt3hU dvw0lNA8LxrPdByL45/1IZshRpHQVSWA6uRgLgZ+gMvGqmemkxWtgWptdWbcSw+2E7bp aeyJjrh9YgY+YsiUlmcCQePqMoVUUoyMzhgFdWqn93bN/bSEItdHjoeB46GlFRKQI8C2 dCqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b="w4/h85cP"; arc=pass (i=1 spf=pass spfdomain=kernel.dk dkim=pass dkdomain=kernel-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-169089-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169089-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 1-20020ac85741000000b00439d3c371b5si8235464qtx.326.2024.05.05.11.04.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 11:04:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169089-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b="w4/h85cP"; arc=pass (i=1 spf=pass spfdomain=kernel.dk dkim=pass dkdomain=kernel-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-169089-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169089-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 669241C20952 for ; Sun, 5 May 2024 18:04:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98F8169D2B; Sun, 5 May 2024 18:04:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="w4/h85cP" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 B5C5E2B9BE for ; Sun, 5 May 2024 18:04:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714932286; cv=none; b=BPTDZ7BYjUHn6TRKAEAu+NfzTGxqpsIQeI8QdTHTY3ejvmP29emumGjwSYIpygOIH9eg3rCv6trHs+zwMZgKHUTyVrLftqU7gSrmJrwLnTbSE0z8NrEWJ00rAodUGvYp2J9lIRXLkC1RcufxzCOGnz/4GEYTL0L508oUIMIc2p0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714932286; c=relaxed/simple; bh=MvgFEIdHJtRnDvyKBZhufXdImvNjTp+dD0weVzheZjg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=YB1mRI8zyOWUUpoH4B/PlqFJilrNbKMhstz0grUW/0RK28AOTV6MApBlx63DbzCAvIKzvI88UrOTdwiNVnMTn/isvGvJ7yWDb4QnmS71XUwzqn1Pj0f9k6RO9zjkPR0cInF5DJMH48MlSPpHVT1U+Abso3aWtwISgUul0T4Q8lc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=w4/h85cP; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1ec4f928c57so3928565ad.3 for ; Sun, 05 May 2024 11:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1714932283; x=1715537083; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=mE6ET/wemNoj1wnsoN5H46vn2H9jFrdPiFfXm3O1q/E=; b=w4/h85cPoz9JrKVApFfzhwqyTk3hafzehD2XG7NNtSIJkUN6u2EfIyUUtNpf9SG2yL W6rdALus2jNJXXvwjvuJ2YTV3zYJdblncEoF1uPLQnao+u8nh1XX1PhOUsQmFsR14I4W MC1Umr7tv0fgbJv1+sUuAzexxKG8j0Uj6G57/BMOdrmG69VYAhAmV/BbzdpOTlDReEkf mJx+YNH5SKRZWCOs6stpErBvVEiEsfx7qfzIwwNWCG07N+gsyJtt+usEjJaQFxA8kU3P lZftFf0JTUkH9nuom4Fw3Va4yeUEtyb+U356wx0/ujdiep7C/KvDYPIRxp/cZcrzb9Hy bvVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714932283; x=1715537083; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mE6ET/wemNoj1wnsoN5H46vn2H9jFrdPiFfXm3O1q/E=; b=NISlWAX1DhyJLtgbmuq2ptuwdnuBjrgM3gGMLzN9En+wVHXjlJkuvPOCnM9EUveT9V LI0X0GSCoRkUoXBMun9ovfCHBv2WCEcc8VzTDu3TUkOBQgsuPFrp/4TVNuwwkFKRngry Vn9kHYM6aXYLApb1N47K0rLpE4tIIKnbRGI3h5Ic4FCjeQM/v+8qwninZ34UuUjIA6Iv fENevnzrrFPD/tUhGxcjq+6U+pGWDpJF3AGIHwMwbNgnPt5oMasxwVgf9pRsY4f+nwEo p0WDFkx1ZfV4AW1McZNBLH4tAkFG7KSFCMPmOaeCJnyQk/+SVVHGUeglqEoSz7pKE7Zo 2tog== X-Forwarded-Encrypted: i=1; AJvYcCXlaGzzzzHBWez1lt0y9MC8rNt/Gv5mIMwoA24GcfyjJtGhoaV6D5hXI5w/uL/sF2f4XPcTMMqkqrb86fF/SN3b9OqJJj68ay0x7Xyf X-Gm-Message-State: AOJu0YwRgQHwEcjkxV+EVS6FOth3Yja8wuQk1KcNTQ9Msn4HxDCt99Nc YBnGHwOYg97EC8TdbCuwuqwWLcMGyZAv4gqtz1rTSIN9kwR7ySWokKUDHHHGeIs= X-Received: by 2002:a17:902:d2d0:b0:1e8:4063:6ded with SMTP id n16-20020a170902d2d000b001e840636dedmr11260813plc.1.1714932282996; Sun, 05 May 2024 11:04:42 -0700 (PDT) Received: from [192.168.1.150] ([198.8.77.194]) by smtp.gmail.com with ESMTPSA id l18-20020a170903121200b001eb03a2bb0asm6700128plh.53.2024.05.05.11.04.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 05 May 2024 11:04:42 -0700 (PDT) Message-ID: Date: Sun, 5 May 2024 12:04:40 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] epoll: be better about file lifetimes To: Linus Torvalds Cc: brauner@kernel.org, christian.koenig@amd.com, dri-devel@lists.freedesktop.org, io-uring@vger.kernel.org, jack@suse.cz, keescook@chromium.org, laura@labbott.name, linaro-mm-sig@lists.linaro.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, minhquangbui99@gmail.com, sumit.semwal@linaro.org, syzbot+045b454ab35fd82a35fb@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com, viro@zeniv.linux.org.uk References: <20240505175556.1213266-2-torvalds@linux-foundation.org> Content-Language: en-US From: Jens Axboe In-Reply-To: <20240505175556.1213266-2-torvalds@linux-foundation.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/5/24 11:55 AM, Linus Torvalds wrote: > epoll can call out to vfs_poll() with a file pointer that may race with > the last 'fput()'. That would make f_count go down to zero, and while > the ep->mtx locking means that the resulting file pointer tear-down will > be blocked until the poll returns, it means that f_count is already > dead, and any use of it won't actually get a reference to the file any > more: it's dead regardless. > > Make sure we have a valid ref on the file pointer before we call down to > vfs_poll() from the epoll routines. > > Link: https://lore.kernel.org/lkml/0000000000002d631f0615918f1e@google.com/ > Reported-by: syzbot+045b454ab35fd82a35fb@syzkaller.appspotmail.com > Reviewed-by: Jens Axboe > Signed-off-by: Linus Torvalds > --- > > Changes since v1: > > - add Link, Reported-by, and Jens' reviewed-by. And sign off on it > because it looks fine to me and we have some testing now. > > - move epi_fget() closer to the user > > - more comments about the background > > - remove the rcu_read_lock(), with the comment explaining why it's not > needed > > - note about returning zero rather than something like EPOLLERR|POLLHUP > for a file that is going away I did look at that 0 return as well and agreed this is the right choice, but adding the comment is a good idea. Anyway, patch still looks fine to me. I'd word wrap the comment section above epi_fget() wider, but that's just a stylistic choice... -- Jens Axboe