lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220401034409.256770-2-chenxiaosong2@huawei.com>
Date:   Fri, 1 Apr 2022 11:44:07 +0800
From:   ChenXiaoSong <chenxiaosong2@...wei.com>
To:     <trond.myklebust@...merspace.com>, <anna@...nel.org>,
        <smayhew@...hat.com>
CC:     <linux-nfs@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <chenxiaosong2@...wei.com>, <liuyongqiang13@...wei.com>,
        <yi.zhang@...wei.com>, <zhangxiaoxu5@...wei.com>
Subject: [PATCH -next,v2 1/3] NFS: return more nuanced writeback errors in nfs_file_write()

Currently, writeback error in address_space flags will not be set in
nfs_mapping_set_error(), return value of nfs_wb_all() is always 0 even if
there is new writeback error. And error from filemap_check_wb_err() is just
used to check, will not be reported to userspace.

Furthermore, filemap_sample_wb_err() always return 0 if old writeback error
have not been consumed. filemap_check_wb_err() will return the old error
even if there is no new writeback error between filemap_sample_wb_err() and
filemap_check_wb_err().

So we still need record writeback error in address_space flags. The writeback
error in address_space flags is not used to be reported to userspace, it is just
used to detect if there is new error while writeback.

generic_perform_write() detect wb error by calling filemap_check_errors():
  generic_perform_write
    nfs_write_end
      nfs_wb_all
        filemap_write_and_wait
          filemap_write_and_wait_range
            filemap_check_errors

filemap_fdatawait_range() detect wb error by calling filemap_check_errors():
  filemap_fdatawait_range
    __filemap_fdatawait_range
    filemap_check_errors

As filemap_check_errors() only report -EIO or -ENOSPC, we must use the more nuanced
writeback error for -EIO by returning -(file->f_mapping->wb_err & MAX_ERRNO).

Fixes: 6c984083ec24 ("NFS: Use of mapping_set_error() results in spurious errors")
Signed-off-by: ChenXiaoSong <chenxiaosong2@...wei.com>
---
 fs/nfs/file.c  | 3 +++
 fs/nfs/write.c | 5 +----
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index b0ca244c50d0..5513ab63c108 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -683,6 +683,9 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
 	}
 	nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written);
 out:
+	/* Use the more nuanced writeback error for -EIO */
+	if (result == -EIO)
+		result = filemap_check_wb_err(file->f_mapping, 0);
 	return result;
 
 out_swapfile:
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index f00d45cf80ef..eec15efb41ab 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -312,10 +312,7 @@ static void nfs_mapping_set_error(struct page *page, int error)
 	struct address_space *mapping = page_file_mapping(page);
 
 	SetPageError(page);
-	filemap_set_wb_err(mapping, error);
-	if (mapping->host)
-		errseq_set(&mapping->host->i_sb->s_wb_err,
-			   error == -ENOSPC ? -ENOSPC : -EIO);
+	mapping_set_error(mapping, error);
 	nfs_set_pageerror(mapping);
 }
 
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ