Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp92379lqh; Fri, 3 May 2024 14:34:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW3QYlBWPKP+5YkgryDv457JCWhhoNGph06IX/S89wEWzl/1h3t7msF1nQiaYVTpdadP6Zz4/unEzdI/y/KEUgcr680clsLHhvZ8/mO5g== X-Google-Smtp-Source: AGHT+IHc+JyIxF2YGDcxT1EHGi7NyuPZIAIzOYPO1U1YzC+Dned4jP8peLquX2dBeMqvMdauwOoe X-Received: by 2002:a05:6359:1396:b0:186:1193:8ccd with SMTP id iq22-20020a056359139600b0018611938ccdmr5725138rwb.23.1714772079986; Fri, 03 May 2024 14:34:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714772079; cv=pass; d=google.com; s=arc-20160816; b=c6N6fLe61HVs3LUEjfzjZ2qx6pRqPZRoFbkGBgtHg0RyzWE4qisnUjLImSp1e2aeHt a76GZfIVuNuHRlD2DSFwbkNJ3p252jHEIWiWt1po5C4lZYJKz6LRABhux2UZl9vlm7DW 8M/LuDvxetJc1fhQNJ/gaCFSGjGA/Wqff6yTBRfxMZeyCIZZLpBLUWvYBvo7smglP9PE HOH0h0zq27JVI7N+G1hEAB9S2dKiSVpfJQDAJJVfhKizf64Av15R4zsByCDA2w71IBGZ qKRP16BxYzajxr4gf+6AiOBni86Cy2pcEpMqFpJ5pEyyyc9NBC7rDQ/DH4+64v6ykoix q44Q== 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=H0cKj1/eeDlsag1nYyx5cuj3RktPC8YvvhuCxa/6SIc=; fh=IC1oAYIoTeO/GkwyInsnOc2qaYW73HmEBaRjHAqRt/Q=; b=AgZDh3Uvz2pkK+Qq4e7bLnUlE0WCd2ZPFmZDCSQpgnmd1ruyFn9ZGxFqjZrLkm/T/G zmajqRCWK/Kem7SjvdIrkqL17YQs74pDoZ3fvBcYtTp36V0nbjS/Vx+SKK2l276+aTPw kIgRvHkbabGaAfkcGlMGNwhDy8M9f1gdvDIPGyO0BMsBBXTLZZLBeDkG4R1krhaDSDsg 0bzb35JP8l7FNaS7tacSyO1PVSh3hWb9hd8UyvGISxqYvmEqfL8EmZQeiHgolD3jneb2 NZLZ37F0bqqu6HC8ixxh26ImfFGhC8B/TZN4be9zpQ8IqP04G7KztsS5j6bugdeN9fDe K/Pg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=I041ed7w; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-168257-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168257-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q137-20020a632a8f000000b0060a08962dcfsi3561108pgq.86.2024.05.03.14.34.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 14:34:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168257-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=I041ed7w; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-168257-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168257-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 7EC322858C6 for ; Fri, 3 May 2024 21:34:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E75F5A4D1; Fri, 3 May 2024 21:33:59 +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="I041ed7w" Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 A580954BD8 for ; Fri, 3 May 2024 21:33:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714772038; cv=none; b=CrM5qVFq5be+EeaJhjM548Rz+7wLO03H+MZhuB4t0IRPUQPhT0GBxh9EQsSYj9CdV76thm0QuKrQGphJf/lQCa7MyPf+e2t2VG0MxbMAw2RsgKUg4eFKfpaOO55DDGSfp5nbTPpxDLQyMfq9nWyWhIBtTZyQTEMh+xa66fryB1A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714772038; c=relaxed/simple; bh=9Qapmfzm6lSNA1KjLLEHmaWSypEB5MZ/Duccomf7UwA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=HbVzQVh1SznxwWGKLm+C9srm60jsrAY6sEzt/M36TXGVwNej9QkmC2cbqoAP0RMb8b+Wu7jFmccXaaYKWQeg13mlzy5kSH7cW0rc3K1UTeaJsx+KeGTbCcFCsqBPxzha6xd7NiSVvyq3sHZRnoNaA/x+Hp//bhxMgsgJ0gPrzH0= 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=I041ed7w; arc=none smtp.client-ip=209.85.218.45 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-ej1-f45.google.com with SMTP id a640c23a62f3a-a599a298990so13922966b.2 for ; Fri, 03 May 2024 14:33:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1714772035; x=1715376835; 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=H0cKj1/eeDlsag1nYyx5cuj3RktPC8YvvhuCxa/6SIc=; b=I041ed7wq74EqHv+lLpw/4OnY1kI3FzQ0ynGOUp7811sa7ORamvQCjH55bC3YnkSar Klx1rhzeK82r5sekSRH+Cic3Wo0satWx94LLNP051CXWwirSPCCliSE8FVQHfxNUSvej uk8KtcOJLyEkqe0pyZgWuEHuRw49MMa4Hn1p4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714772035; x=1715376835; 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=H0cKj1/eeDlsag1nYyx5cuj3RktPC8YvvhuCxa/6SIc=; b=lXX/SL7nJ1CXyaRv9z7YcqEhevezV13m1PDRl4Ea8W4m3mvkB2cp2ZX2WdvRAz9Pgd O/BsXioTV5QupsMQ9v/a73EV11Vt51LD46HByZk9RekjAPJ4kUt2jxtRyFVp9ZmGdHAF erba8WUXhMFk4E60jPwJL3IoUH9t/Edk7EGIAMQBatr5cTBBmBmsMOTkyqiGV9jACnVf 7i3w1+G8zYDuVyHCXwp937KoC1puWXeTq0mCfZjA6svKDeoKPB2rcUHzoHpE3+LnIpkL TH9HcQ9w1jRnFUQTVNaxZdvcLKQcZ6e4kJskd3DdnEbVLw6j+D09iPn8AL2XiShPIK2Z 401Q== X-Forwarded-Encrypted: i=1; AJvYcCU5rMSUUuqYg0swefKCjDaLb4MyBJTdFxdi8S58H3R6iVWjiiPlOX7zqJS9zIC9cV/q2Vn4aX+/68M6skpzXJ4KtvuVNWJLXY0Vqafn X-Gm-Message-State: AOJu0YxSNzTgoRPUImWIIJZI6Ist8ZIudSrfCTAbSc5q+Lxo2NSUT4YU OdkJqb9vVCM6mNStwhHfKWWiiHVkggy5BMv/sVV0xiu63yXo3NPR08sU/+KEH7DeYXBpI0ULojJ fweRToA== X-Received: by 2002:a17:906:2492:b0:a59:9f4e:4e3d with SMTP id e18-20020a170906249200b00a599f4e4e3dmr809157ejb.3.1714772034809; Fri, 03 May 2024 14:33:54 -0700 (PDT) Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com. [209.85.218.43]) by smtp.gmail.com with ESMTPSA id dt14-20020a170907728e00b00a5974a4d662sm1737366ejc.151.2024.05.03.14.33.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 May 2024 14:33:54 -0700 (PDT) Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a599a298990so13918466b.2 for ; Fri, 03 May 2024 14:33:54 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCUl+cnbXHSRYiie7KCI+yuTgiWT4lFBoT3lVlxO++wXyqu8eJVhkU1unjlstugFZWwzbGDn5R7utdynpxC5P/zC4T4Bdt9FBmlajPiQ X-Received: by 2002:a17:906:2c50:b0:a59:761d:8291 with SMTP id f16-20020a1709062c5000b00a59761d8291mr2183947ejh.9.1714772033952; Fri, 03 May 2024 14:33:53 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <202405031110.6F47982593@keescook> <20240503211129.679762-2-torvalds@linux-foundation.org> <20240503212428.GY2118490@ZenIV> In-Reply-To: <20240503212428.GY2118490@ZenIV> From: Linus Torvalds Date: Fri, 3 May 2024 14:33:37 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] epoll: try to be a _bit_ better about file lifetimes To: Al Viro Cc: keescook@chromium.org, axboe@kernel.dk, brauner@kernel.org, christian.koenig@amd.com, dri-devel@lists.freedesktop.org, io-uring@vger.kernel.org, jack@suse.cz, 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 Content-Type: text/plain; charset="UTF-8" On Fri, 3 May 2024 at 14:24, Al Viro wrote: > > Can we get to ep_item_poll(epi, ...) after eventpoll_release_file() > got past __ep_remove()? Because if we can, we have a worse problem - > epi freed under us. Look at the hack in __ep_remove(): if it is concurrent with eventpoll_release_file(), it will hit this code spin_lock(&file->f_lock); if (epi->dying && !force) { spin_unlock(&file->f_lock); return false; } and not free the epi. But as far as I can tell, almost nothing else cares about the f_lock and dying logic. And in fact, I don't think doing spin_lock(&file->f_lock); is even valid in the places that look up file through "epi->ffd.file", because the lock itself is inside the thing that you can't trust until you've taken the lock... So I agree with Kees about the use of "atomic_dec_not_zero()" kind of logic - but it also needs to be in an RCU-readlocked region, I think. I wish epoll() just took the damn file ref itself. But since it relies on the file refcount to release the data structure, that obviously can't work. Linus