Received: by 2002:a05:7208:20d2:b0:82:bbfa:f723 with SMTP id z18csp50460rbz; Tue, 7 May 2024 10:12:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXVgH10/lZbwVmAeADggNqJzOaFpfmiq61/i7qevUgz8FyJiquUqSxrg8sLR5VExoJ4j/QC8qg8uVJ3udVL30dAhVNE6KbnMxeYFRlVJg== X-Google-Smtp-Source: AGHT+IFFEnIxqUPdFdt+aCIe0eehu+Vy3a6FOJfX3j0+AGq8XIRK7iTMJFzfiUP5btKZW6u4CYHP X-Received: by 2002:a17:906:a996:b0:a59:ca9c:4de9 with SMTP id a640c23a62f3a-a59fb9f5184mr5399466b.76.1715101944008; Tue, 07 May 2024 10:12:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715101943; cv=pass; d=google.com; s=arc-20160816; b=T6p44i5YV7RQJn0XyosHY8wPR4ImdMHyJdFO/T+c0/D0olATZFjrJ8PNQemk2UXNtd RRDvVn8cVCaj8LSWrFkUrHudoAe0rIhLFLppdnoMxB3xiSxa3Cnid3f/zfqg/YQ2pw0R oeH4VbRok7sdHna5gneWs6Q4EsTI8IDzw1KII86s5I1wJjlep7EX9kRRzZ78D0hhmFFf uWrmTt+nNsKQF9DGSTm85GKmph4dDlhdVZwqj9rvtml3J/8rj0AeL+8MdYhhy869oR0Q ACu6pIcZzzwBrGDaJ8EcSPXlOpjW7XvESamL0QVORRaj1hSvpejYgewmD0N8Nx4g9I9A IgfQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=BGTjyA9KJ+ZN6kFiIcuqLZ6W/XXJNW0jRsNPu94ZivE=; fh=IV8JACkjsVmsr+J2ASEk+CoeUyB584GcCLWmxsG0z5Y=; b=SntktUDdmfZV1PO6sKoNe64QVPy3KATQ0GbxOnlHbF7knG1RTkyvz759D6YER7yyEN 1yLcIxigrD8JRQptubq7FJcMZZbXGa+IIkEqsWTylY5awbI6fLjHT0XRAHLM7xOdbQ1J 0mJ/QxTQ23hi06svITFIDkxVKWy3km9qNYDRL3gmp7ZTKCJRffhHS39/TDCmvf2qA+rK SOcVP484limJQKt8ZslJGDXcmj+OvzaZIxjJlIcW7rfgaxohMyoju4wKkDRRzKvH2UN/ PBhydm+/msYjbLP4iQwOdSTfuSOwSTlMoYCIRammXC7f/TnqOpxRw+tO9gDsO8bJ71Z2 6hvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=CDnDjLE5; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-171166-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171166-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q18-20020a170906b29200b00a599c6e5eebsi4884502ejz.353.2024.05.07.10.12.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 10:12:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171166-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=@ffwll.ch header.s=google header.b=CDnDjLE5; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-171166-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171166-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 am.mirrors.kernel.org (Postfix) with ESMTPS id CE15A1F25FE7 for ; Tue, 7 May 2024 11:03:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB7F6152162; Tue, 7 May 2024 11:03:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="CDnDjLE5" Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 0906B14EC77 for ; Tue, 7 May 2024 11:02:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715079781; cv=none; b=CRDhFXNxm1bGJQNpUEBrdSRHkvUXOuzsBtIEb9B7q4c5zAJ2B1qPcWgSNOEBr4ytlxQowPde/vvClh4m75bObzO92e3X1UkoiZCP0fALemG0nHmRyX2ZODZGh1FPmGpcE5tlloJvDH2yFh48+BjOGmzp7YuJXBP2Wp3LHVCkehQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715079781; c=relaxed/simple; bh=NYe5+/G+0dLsnUyympMhbfDF1UgMbpQ6AmHg9R3TjSA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uo5FIlD+/vgIAegkZtMwssKZXE1v6o+zeVMph4VktNcYoEtfyn7fb21Gj1YMO7Qt5Sh3TSVDuEZmWf47YXaGgTgDznxNqxc9U+PDSnRax0973RkPwEGdojLo4yMCqdsGyCD8A/urtzQsE9rmSHxp0EWR15rS6JrfPjZa5izbmSw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch; spf=none smtp.mailfrom=ffwll.ch; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b=CDnDjLE5; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ffwll.ch Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-34d24c8fc5cso164238f8f.2 for ; Tue, 07 May 2024 04:02:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1715079778; x=1715684578; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:mail-followup-to:message-id:subject:cc:to :from:date:from:to:cc:subject:date:message-id:reply-to; bh=BGTjyA9KJ+ZN6kFiIcuqLZ6W/XXJNW0jRsNPu94ZivE=; b=CDnDjLE5wmxvCz6JRmrpo/FwsU5ZQAEaBFhky1gBjjH0C2XEgePwbGYYKjLNka91pD hrmCD4gtzwpWbSm5h+XoSSWnFLe62YR2KEWqg8eJM7IXx2gBY+T5YQ0rETGtI/kXDBML 3CrMmEzPhqjwNHUfCmXyHqulbk+pCpeVelxnk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715079778; x=1715684578; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:mail-followup-to:message-id:subject:cc:to :from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BGTjyA9KJ+ZN6kFiIcuqLZ6W/XXJNW0jRsNPu94ZivE=; b=ArQJ5RtdVBwtL1hleik6Q+iGzY149mX6ElH+Wv7//JkUVqO4L2j8qO87x9qzopVcpX 5CkT7dhRpDo9scdLKhK3otakxw8hhZEedXTPf2C06U8JwKxhGB7g5OP8p4leQjLj6/XR DFBh6tsxaZvHUmZV7q2oDrVpH+X+NqNpFL4o04q+KvFur6wSktNCtGRxj+gYvrvOMoYF gIMBhC+P2hXE5v3M6d0J3xRo8whMrZ0MwKVNS2VNrTA2XjBLw/hD62NrgAd0YLOYEj4C HRFuHscZRXC94O9PJftjP+scWRXRszq0s64NoxogRUr2Wr7m0k7lIV5Hd7XmdoYcmuX4 lpWQ== X-Forwarded-Encrypted: i=1; AJvYcCUnQR82rS5sEPGaQ+UA/tqH1XUlSRY8ax9u4Z8EfQ/qGCTllrNxH7B0PPe040YHAvOWzhc2lWFtau+CapvIzYYxfDaTaLU4dTCwGlhJ X-Gm-Message-State: AOJu0YxSi/G28KrprI1hmJtVl2gsW0zkefFAHQEjm8uOdFhzh2NYD+g6 YXj68LeGgbq5skJgXUyU48tSqnYjEsqk70QV22KQQ6fZ0xs4RYbyv0tAteL0jiE= X-Received: by 2002:a5d:6409:0:b0:34d:b76c:cff7 with SMTP id z9-20020a5d6409000000b0034db76ccff7mr8695492wru.3.1715079778329; Tue, 07 May 2024 04:02:58 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id t3-20020a05600001c300b0034df7313bf1sm12829804wrx.0.2024.05.07.04.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 04:02:57 -0700 (PDT) Date: Tue, 7 May 2024 13:02:55 +0200 From: Daniel Vetter To: Christian =?iso-8859-1?Q?K=F6nig?= Cc: Linus Torvalds , Christian Brauner , Al Viro , keescook@chromium.org, axboe@kernel.dk, 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 Subject: Re: [Linaro-mm-sig] Re: [PATCH] epoll: try to be a _bit_ better about file lifetimes Message-ID: Mail-Followup-To: Christian =?iso-8859-1?Q?K=F6nig?= , Linus Torvalds , Christian Brauner , Al Viro , keescook@chromium.org, axboe@kernel.dk, 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 References: <202405031110.6F47982593@keescook> <20240503211129.679762-2-torvalds@linux-foundation.org> <20240503212428.GY2118490@ZenIV> <20240504-wohngebiet-restwert-6c3c94fddbdd@brauner> 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Operating-System: Linux phenom 6.6.15-amd64 On Mon, May 06, 2024 at 04:29:44PM +0200, Christian K?nig wrote: > Am 04.05.24 um 20:20 schrieb Linus Torvalds: > > On Sat, 4 May 2024 at 08:32, Linus Torvalds > > wrote: > > > Lookie here, the fundamental issue is that epoll can call '->poll()' > > > on a file descriptor that is being closed concurrently. > > Thinking some more about this, and replying to myself... > > > > Actually, I wonder if we could *really* fix this by simply moving the > > eventpoll_release() to where it really belongs. > > > > If we did it in file_close_fd_locked(), it would actually make a > > *lot* more sense. Particularly since eventpoll actually uses this: > > > > struct epoll_filefd { > > struct file *file; > > int fd; > > } __packed; > > > > ie it doesn't just use the 'struct file *', it uses the 'fd' itself > > (for ep_find()). > > > > (Strictly speaking, it should also have a pointer to the 'struct > > files_struct' to make the 'int fd' be meaningful). > > While I completely agree on this I unfortunately have to ruin the idea. > > Before we had KCMP some people relied on the strange behavior of eventpoll > to compare struct files when the fd is the same. > > I just recently suggested that solution to somebody at AMD as a workaround > when KCMP is disabled because of security hardening and I'm pretty sure I've > seen it somewhere else as well. > > So when we change that it would break (undocumented?) UAPI behavior. Uh extremely aside, but doesn't this mean we should just enable kcmp on files unconditionally, since there's an alternative? Or a least everywhere CONFIG_EPOLL is enabled? It's really annoying that on some distros/builds we don't have that, and for gpu driver stack reasons we _really_ need to know whether a fd is the same as another, due to some messy uniqueness requirements on buffer objects various drivers have. -Sima > > Regards, > Christian. > > > > > IOW, eventpoll already considers the file _descriptor_ relevant, not > > just the file pointer, and that's destroyed at *close* time, not at > > 'fput()' time. > > > > Yeah, yeah, the locking situation in file_close_fd_locked() is a bit > > inconvenient, but if we can solve that, it would solve the problem in > > a fundamentally different way: remove the ep iterm before the > > file->f_count has actually been decremented, so the whole "race with > > fput()" would just go away entirely. > > > > I dunno. I think that would be the right thing to do, but I wouldn't > > be surprised if some disgusting eventpoll user then might depend on > > the current situation where the eventpoll thing stays around even > > after the close() if you have another copy of the file open. > > > > Linus > > _______________________________________________ > > Linaro-mm-sig mailing list -- linaro-mm-sig@lists.linaro.org > > To unsubscribe send an email to linaro-mm-sig-leave@lists.linaro.org > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch