Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp314676lqh; Sat, 4 May 2024 02:26:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVX/wz1GdtFISDla59C/lB3qZhuJL4VuSH3SPRIwkcNj9tRnX3+y1duQRZ1BaVYgDiIorizbF7HmR2uWpkl6Dk/ukLCu9qVWYHeiKNSyA== X-Google-Smtp-Source: AGHT+IHKy1iF+L8MUJNbIKw40imzwN3Sq5miOgw9H041ogg3+lmZsPD628QsFppCTUgqi7v6HFhw X-Received: by 2002:a50:9b18:0:b0:572:47be:a81e with SMTP id o24-20020a509b18000000b0057247bea81emr3536628edi.40.1714814795250; Sat, 04 May 2024 02:26:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714814795; cv=pass; d=google.com; s=arc-20160816; b=y6GNGeC8gqyd7TkYzJM/JAdBTmn7z+3KrJR5RgSn5PmmQizGoRym2GUEr6ezT1YbTA o6VIQBS1TwJ+678fc+R4eTXBXnw0elSq+5F90LBc0Nkx63PG8BaICkpQyaChL/CCnG5u LS67fNPoLIiwS5qEElDAldPzz5G472sAOzh+oWsxkHdkJMIGksEqotU74YQXd1L1Iyy2 MrEphgJoHNImTGViQtYx2ZaTag8cLvausEBxjDwG3C26f1cgRoj8nmWjMK/KM/qzGBID lLXv+gCZkK/31Uv5MpJyqqtvp4QjR+i9dSGtad1TInjr/+ZrXphWTptjpnEUhFd/DDov nsXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Mu8zeLxosR4oub0+FhU3r/wz/7j/ZYYKIxMdEw1birw=; fh=rE1Lv1walsqBqk0zkOLal4obxWXAioBjxXDU0iT5gdE=; b=bCNfsEI8e71H+vg8zmILkliRdbhUYBzK7SXQ3j42BQbAdLPkMd+45w1d60QbHtmiMc okAaiM0nwo0m24uhqLPj+Z7vdjKEmMx+X3LRpyreHuxFgOLa87Zv3p5AajnUyFLpBwej cuF9231ZOJB2l05ndavCceXHidcJRIVvQRaTJlBtnsFNAfVQkqMrL5mY4AZxcGu2bmwt P4zemc+hYKu5h0Nw6qTlsnFYhxWrFhocLi9w1tS8PMXkdM3NhGLycr8kkNiyqbpidenI 6zhNrovFyeV+6J4PPi62tSTO15dopLR4agi1JsEqmOb5bGcLy7hQxD+SB2IjiY3TPlOi J+0w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=sina.com); spf=pass (google.com: domain of linux-kernel+bounces-168570-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168570-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j16-20020a50ed10000000b0056e5bf5b980si2448178eds.538.2024.05.04.02.26.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 02:26:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168570-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=sina.com); spf=pass (google.com: domain of linux-kernel+bounces-168570-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168570-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 00D061F22376 for ; Sat, 4 May 2024 09:26:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC47C17BAA; Sat, 4 May 2024 09:26:21 +0000 (UTC) Received: from mail115-69.sinamail.sina.com.cn (mail115-69.sinamail.sina.com.cn [218.30.115.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC04C17550 for ; Sat, 4 May 2024 09:26:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=218.30.115.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714814781; cv=none; b=c3ZZFLva0SA5K3gkG+FVxoDOPzCz1EqgoyvsCBJeF8cmw85HFIX8K6E5v1pGrRz8yZROSiQIfu9C4vjV6Z0kADYBXRD+QPZz2nO19x1/ccgeAMUrpvHCXn6ucvK9MSiQf+Z9rJA0VDeRcUvbo4q8jKMWWDi8bpFNH/IwbjqdpMs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714814781; c=relaxed/simple; bh=AdDjbW/grP1x1u3VjOS+sOEPGRWpZymJUUHRPXG9+w4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=l31qUwHrQDMVye1qC1GRqsBSd5IWjG4xbzyHrzlldpck+2092S4xG/M/1Y6Gc+Y59eRATRawnr3gTJCUy34CbF+0Zxt90+HLeOqrnn89RFYvtFz9nQaHJcwdL4EHePUzO6v33SwDCbBeJAG9nco2mog8g1Xu1aGT2CZFYdKDoxI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com; spf=pass smtp.mailfrom=sina.com; arc=none smtp.client-ip=218.30.115.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sina.com X-SMAIL-HELO: localhost.localdomain Received: from unknown (HELO localhost.localdomain)([113.118.66.195]) by sina.com (10.75.12.45) with ESMTP id 6635FF2C00000D24; Sat, 4 May 2024 17:26:06 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com Authentication-Results: sina.com; spf=none smtp.mailfrom=hdanton@sina.com; dkim=none header.i=none; dmarc=none action=none header.from=hdanton@sina.com X-SMAIL-MID: 72955031457681 X-SMAIL-UIID: F6B917177A7A48A99FB77799E769FF11-20240504-172606-1 From: Hillf Danton To: Al Viro Cc: linux-kernel@vger.kernel.org, Linus Torvalds , Kees Cook , Christian Konig , minhquangbui99@gmail.com, syzbot+045b454ab35fd82a35fb@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: Re: [PATCH] epoll: try to be a _bit_ better about file lifetimes Date: Sat, 4 May 2024 17:25:55 +0800 Message-Id: <20240504092555.2071-1-hdanton@sina.com> In-Reply-To: <20240503212428.GY2118490@ZenIV> References: <202405031110.6F47982593@keescook> <20240503211129.679762-2-torvalds@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Fri, 3 May 2024 22:24:28 +0100 Al Viro wrote: > On Fri, May 03, 2024 at 02:11:30PM -0700, Linus Torvalds wrote: > > epoll is a mess, and does various invalid things in the name of > > performance. > > > > Let's try to rein it in a bit. Something like this, perhaps? > > > +/* > > + * The ffd.file pointer may be in the process of > > + * being torn down due to being closed, but we > > + * may not have finished eventpoll_release() yet. > > + * > > + * Technically, even with the atomic_long_inc_not_zero, > > + * the file may have been free'd and then gotten > > + * re-allocated to something else (since files are > > + * not RCU-delayed, they are SLAB_TYPESAFE_BY_RCU). > > 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 - Nope but mtx can help poll go before remove, see below. > epi freed under us. > > If not, we couldn't possibly have reached ->release() yet, let > alone freeing anything. Actually poll can see a file with zero f_count, and LT's idea with trival change survived the syzbot repro [1]. I think fput currently can race with epoll wrt f_count, and checking it in dma-buf is necessary if his idea looks too aggressive. wait_epoll() __fput() do_epoll_wait() eventpoll_release_file() ep_poll() ep_send_events() mutex_lock(&ep->mtx) ep_item_poll() vfs_poll() mutex_unlock(&ep->mtx) mutex_lock(&ep->mtx) dispose = __ep_remove(ep, epi, true) mutex_unlock(&ep->mtx) [1] https://lore.kernel.org/lkml/000000000000f1c99d061798ac6d@google.com/