Received: by 2002:aa6:cad3:0:b0:147:287a:cb84 with SMTP id e19csp776822lky; Mon, 27 Sep 2021 02:43:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJUwiVQ3VSKOqlPeLrjx1hgjH6bmldLVWJ+jT3qzIiBt7PVMa14rCnG8LKu4ntTu5xEdJi X-Received: by 2002:a17:906:2f94:: with SMTP id w20mr27081427eji.14.1632735792397; Mon, 27 Sep 2021 02:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632735792; cv=none; d=google.com; s=arc-20160816; b=BqmeU52VjoH/h8fMNIZ2hOspXmdHv5dnQWl2VfUpJUThRGjDFEAGTevmpva3vqv9tA 9pMK4iKHr811xup/YoVIyYDwthtjBSga1p02GMwGGP/1xsYKy/Sa4FUhvkCvYdC6DlQK CiW75iI5Ck0eNnghOuwb3vVk6v49Tbn8+bZgFeqfRq8fiOrJ4dCbojWR376KWrAYo2Wp RMNj/tCdviaJRA/debwje9A1MB1+bMt1An6ysNvpb225ftNftGO6t+npjavC/A5ubs7t zVLBecef0S50zUR4K1VCBKE7jIZTk3ZFSEy99wJwB458+QFhfmJFsr4o+xrbUBaS9xp0 hBxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ECuwL8PYjygsXbJeg0HIr0JMSqu9hGq4/KV9n5A6dtA=; b=ZxTD8k1F9JjUYDZdeIAi3L5n1vx9/KALnfHZGIe726MnA68NqSxtF48ay4V2hxixdo 0NF6/pCRhFVPeu9gKZuG4zOOsllLLGfHa6Bp5v8uZ3o9txZZOePwRv0zou7rCKZF/kHS ZNdJtchxAkqsc4JGAINwNoUmy22rTZHpkR8OtdJM7gwjIhSGotNFsNsMaTwkpbW2fOO3 p4/zkNiaxpZqnG2mguA7CWVb8pibCeWGI8V51EaV0bJmvcbkbueIIAAiS9JzqPjjpdGE XpdmnWTar4B1+NpO6nEEl1yDtb1r691ppXgvjPsFdia2UnI+/jIEON7aLHmtXxnj3quL V13Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=CQILzEC7; 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 i13si2837312edx.489.2021.09.27.02.42.49; Mon, 27 Sep 2021 02:43:12 -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; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=CQILzEC7; 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 S233675AbhI0Jkl (ORCPT + 99 others); Mon, 27 Sep 2021 05:40:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233680AbhI0Jkl (ORCPT ); Mon, 27 Sep 2021 05:40:41 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B149C061714 for ; Mon, 27 Sep 2021 02:39:03 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id v18so31429671edc.11 for ; Mon, 27 Sep 2021 02:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ECuwL8PYjygsXbJeg0HIr0JMSqu9hGq4/KV9n5A6dtA=; b=CQILzEC7pzKjk9XO7pFtNfZ/7DXYnBmKVK4NBNhCa1P8Ky74nwcKlLrArJ/RA4o5Ee BPMosUGfUDgE+agrVRTsixyT/PB+0Vaa6wqVMRoRrYxCvhAN1UHuWbpBgYjqE04C28Lt xolW6ymtZCXimpknOdvLPeKaUTjEyYKUfIGdE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ECuwL8PYjygsXbJeg0HIr0JMSqu9hGq4/KV9n5A6dtA=; b=QJ1okZa/UuxyMrsxOjC+/HMnMREU5/xlVSWXrtj50ZHm9R1emp3P7zVek12z+qWl7h Q2wTNI3lpsM5N1ePGGdPx+iR0IaTDZgwXoNujlouQtK0PWSBHlmm1j2IMGoaAgzrj8HN FisgVwEomWOCrdOtMS5GWTbGjC3uKI7d2sGzbIMOJXuGDeCGHp3eslH+sAZsTd+5HBjP Uy0Jb5Ov7eQW9+2LlAfXRFZ71pcFGLP+CAzMxIn/q98zOH1xjqkMi2vIQJ3t/mKAzN2n /H3o2eCI7XHAb09+SCNnroFnknx9hHhRsXmO1JRAMQ4qctbOyOGKaoPl4PZK6eYBeQbb w1ZA== X-Gm-Message-State: AOAM531izb380wZ0W3uPVnwr7rZsA8/aOMFHkV1y9h/azL9SyatOm7zQ WN9x8RTQ65B0TFaGcomaZKLq/Q== X-Received: by 2002:a17:906:e216:: with SMTP id gf22mr25286699ejb.357.1632735541800; Mon, 27 Sep 2021 02:39:01 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-86-101-169-16.catv.broadband.hu. [86.101.169.16]) by smtp.gmail.com with ESMTPSA id dt4sm3169554ejb.27.2021.09.27.02.39.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 02:39:01 -0700 (PDT) Date: Mon, 27 Sep 2021 11:38:58 +0200 From: Miklos Szeredi To: Huang Jianan Cc: Chengguang Xu , overlayfs , linux-erofs@lists.ozlabs.org, xiang@kernel.org, chao@kernel.org, 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, Chengguang Xu Subject: Re: [PATCH v3] ovl: fix null pointer when filesystemdoesn'tsupportdirect IO Message-ID: References: <9ef909de-1854-b4be-d272-2b4cda52329f@oppo.com> <20210922072326.3538-1-huangjianan@oppo.com> <919e929d-6af7-b729-9fd2-954cd1e52999@oppo.com> <314324e7-02d7-dc43-b270-fb8117953549@139.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 22, 2021 at 04:00:47PM +0200, Miklos Szeredi wrote: > First let's fix the oops: ovl_read_iter()/ovl_write_iter() must check > real file's ->direct_IO if IOCB_DIRECT is set in iocb->ki_flags and > return -EINVAL if not. And here's that fix. Please test. Thanks, Miklos --- From: Miklos Szeredi Subject: ovl: fix IOCB_DIRECT if underlying fs doesn't support direct IO Normally the check at open time suffices, but e.g loop device does set IOCB_DIRECT after doing its own checks (which are not sufficent for overlayfs). Make sure we don't call the underlying filesystem read/write method with the IOCB_DIRECT if it's not supported. Reported-by: Huang Jianan Fixes: 16914e6fc7e1 ("ovl: add ovl_read_iter()") Cc: # v4.19 Signed-off-by: Miklos Szeredi --- fs/overlayfs/file.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -296,6 +296,12 @@ static ssize_t ovl_read_iter(struct kioc if (ret) return ret; + ret = -EINVAL; + if (iocb->ki_flags & IOCB_DIRECT && + (!real.file->f_mapping->a_ops || + !real.file->f_mapping->a_ops->direct_IO)) + goto out_fdput; + old_cred = ovl_override_creds(file_inode(file)->i_sb); if (is_sync_kiocb(iocb)) { ret = vfs_iter_read(real.file, iter, &iocb->ki_pos, @@ -320,7 +326,7 @@ static ssize_t ovl_read_iter(struct kioc out: revert_creds(old_cred); ovl_file_accessed(file); - +out_fdput: fdput(real); return ret; @@ -349,6 +355,12 @@ static ssize_t ovl_write_iter(struct kio if (ret) goto out_unlock; + ret = -EINVAL; + if (iocb->ki_flags & IOCB_DIRECT && + (!real.file->f_mapping->a_ops || + !real.file->f_mapping->a_ops->direct_IO)) + goto out_fdput; + if (!ovl_should_sync(OVL_FS(inode->i_sb))) ifl &= ~(IOCB_DSYNC | IOCB_SYNC); @@ -384,6 +396,7 @@ static ssize_t ovl_write_iter(struct kio } out: revert_creds(old_cred); +out_fdput: fdput(real); out_unlock: