mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2]  jfs: add checks read-only to prevent NULL pointer deref
@ 2024-12-24 14:49 Vasiliy Kovalev
  2024-12-24 14:49 ` [PATCH 1/2] jfs: add check read-only before txBeginAnon() call Vasiliy Kovalev
  2024-12-24 14:49 ` [PATCH 2/2] jfs: add check read-only before truncation in jfs_truncate_nolock() Vasiliy Kovalev
  0 siblings, 2 replies; 3+ messages in thread
From: Vasiliy Kovalev @ 2024-12-24 14:49 UTC (permalink / raw)
  To: Dave Kleikamp, Josef Bacik, Matthew Wilcox, Christian Brauner,
	jfs-discussion, linux-kernel
  Cc: lvc-project, kovalev, syzbot+4e89b5368baba8324e07

These two patches add read-only checks in JFS functions to
prevent attempts to modify a read-only filesystem, which could
lead to NULL pointer dereferencing. 

Reported-by: syzbot+4e89b5368baba8324e07@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=4e89b5368baba8324e07

[PATCH 1/2] jfs: add check read-only before txBeginAnon() call
[PATCH 2/2] jfs: add check read-only before truncation in jfs_truncate_nolock()


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] jfs: add check read-only before txBeginAnon() call
  2024-12-24 14:49 [PATCH 0/2] jfs: add checks read-only to prevent NULL pointer deref Vasiliy Kovalev
@ 2024-12-24 14:49 ` Vasiliy Kovalev
  2024-12-24 14:49 ` [PATCH 2/2] jfs: add check read-only before truncation in jfs_truncate_nolock() Vasiliy Kovalev
  1 sibling, 0 replies; 3+ messages in thread
From: Vasiliy Kovalev @ 2024-12-24 14:49 UTC (permalink / raw)
  To: Dave Kleikamp, Josef Bacik, Matthew Wilcox, Christian Brauner,
	jfs-discussion, linux-kernel
  Cc: lvc-project, kovalev, syzbot+4e89b5368baba8324e07

Added a read-only check before calling `txBeginAnon` in `extAlloc`
and `extRecord`. This prevents modification attempts on a read-only
mounted filesystem, avoiding potential errors or crashes.

Call trace:
 txBeginAnon+0xac/0x154
 extAlloc+0xe8/0xdec fs/jfs/jfs_extent.c:78
 jfs_get_block+0x340/0xb98 fs/jfs/inode.c:248
 __block_write_begin_int+0x580/0x166c fs/buffer.c:2128
 __block_write_begin fs/buffer.c:2177 [inline]
 block_write_begin+0x98/0x11c fs/buffer.c:2236
 jfs_write_begin+0x44/0x88 fs/jfs/inode.c:299

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>
---
 fs/jfs/jfs_extent.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/jfs/jfs_extent.c b/fs/jfs/jfs_extent.c
index 63d21822d309be..46529bcc8297ea 100644
--- a/fs/jfs/jfs_extent.c
+++ b/fs/jfs/jfs_extent.c
@@ -74,6 +74,11 @@ extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, bool abnr)
 	int rc;
 	int xflag;
 
+	if (isReadOnly(ip)) {
+		jfs_error(ip->i_sb, "read-only filesystem\n");
+		return -EIO;
+	}
+
 	/* This blocks if we are low on resources */
 	txBeginAnon(ip->i_sb);
 
@@ -253,6 +258,11 @@ int extRecord(struct inode *ip, xad_t * xp)
 {
 	int rc;
 
+	if (isReadOnly(ip)) {
+		jfs_error(ip->i_sb, "read-only filesystem\n");
+		return -EIO;
+	}
+
 	txBeginAnon(ip->i_sb);
 
 	mutex_lock(&JFS_IP(ip)->commit_mutex);
-- 
2.33.8


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] jfs: add check read-only before truncation in jfs_truncate_nolock()
  2024-12-24 14:49 [PATCH 0/2] jfs: add checks read-only to prevent NULL pointer deref Vasiliy Kovalev
  2024-12-24 14:49 ` [PATCH 1/2] jfs: add check read-only before txBeginAnon() call Vasiliy Kovalev
@ 2024-12-24 14:49 ` Vasiliy Kovalev
  1 sibling, 0 replies; 3+ messages in thread
From: Vasiliy Kovalev @ 2024-12-24 14:49 UTC (permalink / raw)
  To: Dave Kleikamp, Josef Bacik, Matthew Wilcox, Christian Brauner,
	jfs-discussion, linux-kernel
  Cc: lvc-project, kovalev, syzbot+4e89b5368baba8324e07

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>
---
 fs/jfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c
index 07cfdc4405968b..60fc92dee24d20 100644
--- a/fs/jfs/inode.c
+++ b/fs/jfs/inode.c
@@ -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;
 	}
-- 
2.33.8


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-12-24 14:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-24 14:49 [PATCH 0/2] jfs: add checks read-only to prevent NULL pointer deref Vasiliy Kovalev
2024-12-24 14:49 ` [PATCH 1/2] jfs: add check read-only before txBeginAnon() call Vasiliy Kovalev
2024-12-24 14:49 ` [PATCH 2/2] jfs: add check read-only before truncation in jfs_truncate_nolock() Vasiliy Kovalev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®