Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp480890pxb; Wed, 22 Sep 2021 06:33:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsJFo5dEx+37OtuYbSwmG//YvNonV7AFQq9+ZF6vhvbVcFXfgtvYcSF83zjiQoAqh65yrU X-Received: by 2002:a5d:63c5:: with SMTP id c5mr41924751wrw.135.1632317593952; Wed, 22 Sep 2021 06:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632317593; cv=none; d=google.com; s=arc-20160816; b=dtlkvZFSPkEt2+o24RnSnrAyj6Na2DHIxn/M6I4d8zxuPeCwsS6LrCPgoS0PFC3ykM oubvVaxyny65FD+u8HoUOPPRDMdfYAmnxPZYQrwnvRsfYv4VbcyqJFRwmJCLxecaSD7/ 6HKSXPmnxEQX4s51t1G13a00LanLpkaFzutbDKndHD8G92qyWW9/CzsgNhF+TUm/5tyK yf6VEAFfhOf/6SNOPCHXAg9S2bpzO7Jtr8u8+AzLh9YMNcOn+pqM3UgMpG5aNVpcMxQQ rkvv0SiQviZBuTM6MlqvQ8l1FFOTnqfJ6hRfNkRcmNZq3mGBTMZixUHTfrXoHAzwfJD/ OaAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:subject:from:user-agent:mime-version:date:message-id; bh=NngzLWV1PN/WynDAZcCaPT7QPbeqGerfBIx6TT4t15U=; b=pqIAymtlWKy1Wq4PrLBacKdyp5yMGhryEj7/xx9k9/qybQnhhIzXsKFVolUpqOlYZs M0m9wxxJcmGUTcM1zIwtRBzKZq67050owUxTCTCeSREY6ELNokpXXh0yzxn34s+kiID+ 8BqBQ5mDkG/5LcKx0adKDAd0Vhk49KiOVB7XL35/6SQpT1M/at9CKHdxVPHxsD0CKhvT /buG615zx0A0hif18MArxpWDxLLqkVh/vBRAINoJXbH2fUKgijok6zJTWd6lcIsj4pii 3BPtTaS72GvS8SRQ2zRHP3saeMGqLBheJ1Bjenf4AQAjiTtZu14VXdqZsHCnou6EIx+z osaw== ARC-Authentication-Results: i=1; mx.google.com; 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 v14si2709092edb.187.2021.09.22.06.32.48; Wed, 22 Sep 2021 06:33:13 -0700 (PDT) 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; 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 S232199AbhIVNcB (ORCPT + 99 others); Wed, 22 Sep 2021 09:32:01 -0400 Received: from n169-114.mail.139.com ([120.232.169.114]:14867 "EHLO n169-114.mail.139.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231864AbhIVNcA (ORCPT ); Wed, 22 Sep 2021 09:32:00 -0400 X-Greylist: delayed 575 seconds by postgrey-1.27 at vger.kernel.org; Wed, 22 Sep 2021 09:31:57 EDT X-RM-TagInfo: emlType=0 X-RM-SPAM: X-RM-SPAM-FLAG: 00000000 Received: from [192.168.255.10] (unknown[113.108.77.67]) by rmsmtp-lg-appmail-39-12053 (RichMail) with SMTP id 2f15614b2db0269-70997; Wed, 22 Sep 2021 21:20:51 +0800 (CST) X-RM-TRANSID: 2f15614b2db0269-70997 Message-ID: <314324e7-02d7-dc43-b270-fb8117953549@139.com> Date: Wed, 22 Sep 2021 21:20:50 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.1.1 From: Chengguang Xu Subject: Re: [PATCH v3] ovl: fix null pointer when filesystemdoesn'tsupportdirect IO To: Huang Jianan , linux-unionfs@vger.kernel.org, miklos@szeredi.hu, linux-erofs@lists.ozlabs.org, xiang@kernel.org, chao@kernel.org Cc: guoweichao@oppo.com, yh@oppo.com, zhangshiming@oppo.com, guanyuwei@oppo.com, jnhuang95@gmail.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, cgxu519@mykernel.net References: <9ef909de-1854-b4be-d272-2b4cda52329f@oppo.com> <20210922072326.3538-1-huangjianan@oppo.com> <919e929d-6af7-b729-9fd2-954cd1e52999@oppo.com> In-Reply-To: <919e929d-6af7-b729-9fd2-954cd1e52999@oppo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/9/22 16:24, Huang Jianan 写道: > > > 在 2021/9/22 16:06, Chengguang Xu 写道: >> 在 2021/9/22 15:23, Huang Jianan 写道: >>> From: Huang Jianan >>> >>> At present, overlayfs provides overlayfs inode to users. Overlayfs >>> inode provides ovl_aops with noop_direct_IO to avoid open failure >>> with O_DIRECT. But some compressed filesystems, such as erofs and >>> squashfs, don't support direct_IO. >>> >>> Users who use f_mapping->a_ops->direct_IO to check O_DIRECT support, >>> will read file through this way. This will cause overlayfs to access >>> a non-existent direct_IO function and cause panic due to null pointer: >> >> I just looked around the code more closely, in open_with_fake_path(), >> >> do_dentry_open() has already checked O_DIRECT open flag and >> a_ops->direct_IO of underlying real address_space. >> >> Am I missing something? >> >> > > It seems that loop_update_dio will set lo->use_dio after open file > without set O_DIRECT. > loop_update_dio will check f_mapping->a_ops->direct_IO but it deal > with ovl_aops with > noop _direct_IO. > > So I think we still need a new aops? It means we should only set ->direct_IO for overlayfs inodes whose underlying fs has DIRECT IO ability. Hi Miklos, Is it right solution for this kind of issue? What do you think? Thanks, Chengguang > > Thanks, > Jianan > >> Thanks, >> >> Chengguang >> >> >>> >>> Kernel panic - not syncing: CFI failure (target: 0x0) >>> CPU: 6 PID: 247 Comm: loop0 >>> Call Trace: >>>   panic+0x188/0x45c >>>   __cfi_slowpath+0x0/0x254 >>>   __cfi_slowpath+0x200/0x254 >>>   generic_file_read_iter+0x14c/0x150 >>>   vfs_iocb_iter_read+0xac/0x164 >>>   ovl_read_iter+0x13c/0x2fc >>>   lo_rw_aio+0x2bc/0x458 >>>   loop_queue_work+0x4a4/0xbc0 >>>   kthread_worker_fn+0xf8/0x1d0 >>>   loop_kthread_worker_fn+0x24/0x38 >>>   kthread+0x29c/0x310 >>>   ret_from_fork+0x10/0x30 >>> >>> The filesystem may only support direct_IO for some file types. For >>> example, erofs supports direct_IO for uncompressed files. So return >>> -EINVAL when the file doesn't support direct_IO to fix this problem. >>> >>> Fixes: 5b910bd615ba ("ovl: fix GPF in swapfile_activate of file from >>> overlayfs over xfs") >>> Signed-off-by: Huang Jianan >>> --- >>> change since v2: >>>   - Return error in ovl_open directly. (Chengguang Xu) >>> >>> Change since v1: >>>   - Return error to user rather than fall back to buffered io. >>> (Chengguang Xu) >>> >>>   fs/overlayfs/file.c | 4 ++++ >>>   1 file changed, 4 insertions(+) >>> >>> diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c >>> index d081faa55e83..a0c99ea35daf 100644 >>> --- a/fs/overlayfs/file.c >>> +++ b/fs/overlayfs/file.c >>> @@ -157,6 +157,10 @@ static int ovl_open(struct inode *inode, struct >>> file *file) >>>       if (IS_ERR(realfile)) >>>           return PTR_ERR(realfile); >>>   +    if ((f->f_flags & O_DIRECT) && (!realfile->f_mapping->a_ops || >>> +        !realfile->f_mapping->a_ops->direct_IO)) >>> +        return -EINVAL; >>> + >>>       file->private_data = realfile; >>>         return 0; >> >