]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
jfs: add check read-only before truncation in jfs_truncate_nolock()
authorVasiliy Kovalev <kovalev@altlinux.org>
Tue, 24 Dec 2024 14:49:14 +0000 (17:49 +0300)
committerDave Kleikamp <dave.kleikamp@oracle.com>
Wed, 19 Feb 2025 21:29:08 +0000 (15:29 -0600)
Added a check for "read-only" mode in the `jfs_truncate_nolock`
function to avoid errors related to writing to a read-only
filesystem.

Call stack:

block_write_begin() {
  jfs_write_failed() {
    jfs_truncate() {
      jfs_truncate_nolock() {
        txEnd() {
          ...
          log = JFS_SBI(tblk->sb)->log;
          // (log == NULL)

If the `isReadOnly(ip)` condition is triggered in
`jfs_truncate_nolock`, the function execution will stop, and no
further data modification will occur. Instead, the `xtTruncate`
function will be called with the "COMMIT_WMAP" flag, preventing
modifications in "read-only" mode.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: syzbot+4e89b5368baba8324e07@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=4e89b5368baba8324e07
Signed-off-by: Vasiliy Kovalev <kovalev@altlinux.org>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
fs/jfs/inode.c

index 07cfdc4405968b86588fbbf8dfc8c7dc9d4cf1ee..60fc92dee24d2059b2d4780accac88c610131536 100644 (file)
@@ -369,7 +369,7 @@ void jfs_truncate_nolock(struct inode *ip, loff_t length)
 
        ASSERT(length >= 0);
 
-       if (test_cflag(COMMIT_Nolink, ip)) {
+       if (test_cflag(COMMIT_Nolink, ip) || isReadOnly(ip)) {
                xtTruncate(0, ip, length, COMMIT_WMAP);
                return;
        }