Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp35960pxb; Thu, 21 Jan 2021 00:10:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIqD1iscD9CAVP4y2aVfGCiEDzMGZqukTOAPHt70iFV4wmXoXa00ikWNcoBeEYkuGsQnB0 X-Received: by 2002:a17:906:2f07:: with SMTP id v7mr8381026eji.343.1611216613337; Thu, 21 Jan 2021 00:10:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611216613; cv=none; d=google.com; s=arc-20160816; b=yNN6KYwAskeo5gUGcnxGLjAcscP0QhGQnN7XovqkGmr2j1KWKSNm38wHDcVAZ/UDL/ nq9lq9IjXSjjGfcAXrBHmoJH30u9OeqSvfCJyYbjt2GyhpwLawGLJvrmVfgsHiX5CEy4 C4v19G7LI1hNo7U2n1kSiuhrgVwxqqpZKk6F3GZtLzby6+hqcGyX/69ClTYhLzxIwwnD ZttPoez9k4v5a4TwgCMSwv5Kx0Mbq6VFdh/Oj4ajrSQ9nIO7yY/yCK5NUIsMhpE3nwm3 wzLocMQePsRWMPNkhmsrGgLg0sIRA3lXRfyLGaHl9xp89fL4yd1qvFzpNIdpBOD5+npA LAlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=HJKAVHbB5ive9I6qDPNYB34EvzgegIV7pqrbZWLDm6A=; b=jmbXiNKvZNN/GL9QdkR0Wzjnq2PQoliqHGiZ1xlQX3fahr2wcm/7nOBDD/diJubWgt oBd5t3OIAVRRWgcQmyIR5PW61Xhs3mz1nFwNJtbsoulRNSnZ1K/CRIl7mn0AGaY9i7ur c6c6ZH8aDzwSAbCFamjZJ8AJZlD/bsJBzjQZP+UbP1WRI7883ALnSL0xNL8XjGGybAbZ n7fBxCHecmZ1+Xpx2+hL7uZ6HmcMQuYbAT396VmZ+Pal7bHRtjsohk4P3MKlASArDHEs 4M7a0X7rhzfkSGPxrtX4Fhb4P237MgEYcD8sIWu4wC5hcKbrQ1S7DY7FGot1QP2O/CSm wm5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b="fARiv+9/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y36si1938089ede.158.2021.01.21.00.09.49; Thu, 21 Jan 2021 00:10:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b="fARiv+9/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726648AbhAUIIq (ORCPT + 99 others); Thu, 21 Jan 2021 03:08:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727630AbhAUIIV (ORCPT ); Thu, 21 Jan 2021 03:08:21 -0500 Received: from mail-vs1-xe2f.google.com (mail-vs1-xe2f.google.com [IPv6:2607:f8b0:4864:20::e2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7778FC061757 for ; Thu, 21 Jan 2021 00:07:38 -0800 (PST) Received: by mail-vs1-xe2f.google.com with SMTP id n18so574153vsa.12 for ; Thu, 21 Jan 2021 00:07:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=HJKAVHbB5ive9I6qDPNYB34EvzgegIV7pqrbZWLDm6A=; b=fARiv+9/l4+YDpEc+1svLF0/4kuY9Nlu92GJlRrzukZb8yv5BGcyBbwSlvPVB+KdcO wiFvAeUtE8D6PgZsORFxrtsijnvcYw9tfF5hJR/HnwrPT3miP8Sue94ecAOMuD9NNbBb ETFsiAOga8TFdekG5A4OrU6YMeJKlpu+MeRAU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=HJKAVHbB5ive9I6qDPNYB34EvzgegIV7pqrbZWLDm6A=; b=fglbHVPGnZBKBhKXZ/m6wrfxUsx1w99rDQtdGAsDZl4qnDU1cKMjUSKgTHj3X6PLZx /zrAEOteoaQU4XMhPicTpN6dS6u2sRT2IevWBuDaaylDf6Z34/kGzpKuJ2EFFbXupGP6 Abd49O5GoZyXYjXNsmXi2OtB7ZwL7v3B8vNK0eU/FKFoVj37klxEAZCVoxODTvU99yU5 6AkT6clyNJTVZAvbah3rtG0WMUkMT79AYLg4IQO6AJZTVFtLfjpVuvXn6tc0C9gM62x0 04Qlt+trUHcv06Bm8w/Cf8Vp2yemfNWo5C7CjQaddRJ3V7AuLHi8jifT1xeirbiiE3Y/ H9PQ== X-Gm-Message-State: AOAM533aGcdEw8yWO5IzeRzQU1ycmrBSV6n4mx8dIlT6VuDdchk3imHP ed5idYZpfQBI3M6kYbw9rkX0ea3ZYr/m9sHI1/cSvg== X-Received: by 2002:a67:8844:: with SMTP id k65mr8969325vsd.9.1611216457611; Thu, 21 Jan 2021 00:07:37 -0800 (PST) MIME-Version: 1.0 References: <20210105003611.194511-1-icenowy@aosc.io> <20210120102045.GD1236412@miu.piliscsaba.redhat.com> <83bb613212ee81648e5bf7c0f9cd3219e0046f80.camel@aosc.io> In-Reply-To: <83bb613212ee81648e5bf7c0f9cd3219e0046f80.camel@aosc.io> From: Miklos Szeredi Date: Thu, 21 Jan 2021 09:07:26 +0100 Message-ID: Subject: Re: [PATCH v3] ovl: use a dedicated semaphore for dir upperfile caching To: Icenowy Zheng Cc: Amir Goldstein , Xiao Yang , overlayfs , linux-kernel , stable Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 21, 2021 at 4:43 AM Icenowy Zheng wrote: > > =E5=9C=A8 2021-01-20=E6=98=9F=E6=9C=9F=E4=B8=89=E7=9A=84 11:20 +0100=EF= =BC=8CMiklos Szeredi=E5=86=99=E9=81=93=EF=BC=9A > > On Tue, Jan 05, 2021 at 08:47:41AM +0200, Amir Goldstein wrote: > > > On Tue, Jan 5, 2021 at 2:36 AM Icenowy Zheng > > > wrote: > > > > > > > > The function ovl_dir_real_file() currently uses the semaphore of > > > > the > > > > inode to synchronize write to the upperfile cache field. > > > > > > Although the inode lock is a rw_sem it is referred to as the "inode > > > lock" > > > and you also left semaphore in the commit subject. > > > No need to re-post. This can be fixed on commit. > > > > > > > > > > > However, this function will get called by ovl_ioctl_set_flags(), > > > > which > > > > utilizes the inode semaphore too. In this case > > > > ovl_dir_real_file() will > > > > try to claim a lock that is owned by a function in its call > > > > stack, which > > > > won't get released before ovl_dir_real_file() returns. > > > > > > > > Define a dedicated semaphore for the upperfile cache, so that the > > > > deadlock won't happen. > > > > > > > > Fixes: 61536bed2149 ("ovl: support [S|G]ETFLAGS and > > > > FS[S|G]ETXATTR ioctls for directories") > > > > Cc: stable@vger.kernel.org # v5.10 > > > > Signed-off-by: Icenowy Zheng > > > > --- > > > > Changes in v2: > > > > - Fixed missing replacement in error handling path. > > > > Changes in v3: > > > > - Use mutex instead of semaphore. > > > > > > > > fs/overlayfs/readdir.c | 10 +++++----- > > > > 1 file changed, 5 insertions(+), 5 deletions(-) > > > > > > > > diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c > > > > index 01620ebae1bd..3980f9982f34 100644 > > > > --- a/fs/overlayfs/readdir.c > > > > +++ b/fs/overlayfs/readdir.c > > > > @@ -56,6 +56,7 @@ struct ovl_dir_file { > > > > struct list_head *cursor; > > > > struct file *realfile; > > > > struct file *upperfile; > > > > + struct mutex upperfile_mutex; > > > > > > That's a very specific name. > > > This mutex protects members of struct ovl_dir_file, which could > > > evolve > > > into struct ovl_file one day (because no reason to cache only dir > > > upper file), > > > so I would go with a more generic name, but let's leave it to > > > Miklos to decide. > > > > > > He could have a different idea altogether for fixing this bug. > > > > How about this (untested) patch? > > > > It's a cleanup as well as a fix, but maybe we should separate the > > cleanup from > > the fix... > > If you are going to post this, feel free to add > > Tested-by: Icenowy Zheng Okay, thanks. > (And if you remove the IS_ERR(realfile) part, the tested-by tag still > applies.) Dropping the IS_ERR(realfile) here would mean having to add the same check before relevant fput() calls, which would make it more complex not less. Or did you mean something else? Thanks, Miklos