Linux-EROFS Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry
       [not found] ` <40746a9ae6d2e76d748ec0bf7710bba7e49a53ac.camel@huaweicloud.com>
@ 2024-03-03 14:54   ` Tetsuo Handa
  2024-03-03 23:53     ` Gao Xiang
                       ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Tetsuo Handa @ 2024-03-03 14:54 UTC (permalink / raw)
  To: syzbot, syzkaller-bugs, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu
  Cc: linux-erofs, linux-kernel

On 2024/02/20 19:40, Roberto Sassu wrote:
> On Mon, 2024-02-19 at 22:41 -0800, syzbot wrote:
>> Hello,
>>
>> syzbot found the following issue on:
>>
>> HEAD commit:    4f5e5092fdbf Merge tag 'net-6.8-rc5' of git://git.kernel.o..
>> git tree:       upstream
>> console output: https://syzkaller.appspot.com/x/log.txt?x=135ba81c180000
>> kernel config:  https://syzkaller.appspot.com/x/.config?x=e3dd779fba027968
>> dashboard link: https://syzkaller.appspot.com/bug?extid=7bc44a489f0ef0670bd5
>> compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

> I would add the VFS people in CC, in case they have some ideas.

This is an erofs bug. Since the filesystem image in the reproducer
is crafted, decompression generates bogus result and
z_erofs_transform_plain() misbehaves.

You can obtain a single-threaded reproducer from
https://syzkaller.appspot.com/x/repro.c?x=1256096a180000 with below diff.

----------------------------------------
--- old/1256096a180000.c
+++ new/1256096a180000.c
@@ -676,6 +676,6 @@
   syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
           /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
           /*offset=*/0ul);
-  loop();
+  execute_one();
   return 0;
 }
----------------------------------------

With CONFIG_EROFS_FS_DEBUG=y, the reproducer hits DBG_BUGON().
With debug printk() shown below, you can get output shown below.

----------------------------------------
diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index d4cee95af14c..f221133a0731 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -323,7 +323,11 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
 	unsigned int cur = 0, ni = 0, no, pi, po, insz, cnt;
 	u8 *kin;
 
-	DBG_BUGON(rq->outputsize > rq->inputsize);
+	if (rq->outputsize > rq->inputsize) {
+		pr_err("rq->inputsize=%u rq->outputsize=%u\n", rq->inputsize, rq->outputsize);
+		pr_err("rq->pageofs_in=%u rq->pageofs_out=%u\n", rq->pageofs_in, rq->pageofs_out);
+		pr_err("nrpages_in=%u nrpages_out=%u\n", nrpages_in, nrpages_out);
+	}
 	if (rq->alg == Z_EROFS_COMPRESSION_INTERLACED) {
 		cur = bs - (rq->pageofs_out & (bs - 1));
 		pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK;
@@ -352,7 +356,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
 		do {
 			no = (rq->pageofs_out + cur + pi) >> PAGE_SHIFT;
 			po = (rq->pageofs_out + cur + pi) & ~PAGE_MASK;
-			DBG_BUGON(no >= nrpages_out);
+			if (no >= nrpages_out)
+				pr_err("no=%u nrpages_out=%u\n", no, nrpages_out);
 			cnt = min(insz - pi, PAGE_SIZE - po);
 			if (rq->out[no] == rq->in[ni]) {
 				memmove(kin + po,
@@ -366,7 +371,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
 		} while (pi < insz);
 		kunmap_local(kin);
 	}
-	DBG_BUGON(ni > nrpages_in);
+	if (ni > nrpages_in)
+		pr_err("ni=%u nrpages_in=%u\n", ni, nrpages_in);
 	return 0;
 }
 
----------------------------------------

----------------------------------------
[  138.991810][ T2983] loop0: detected capacity change from 0 to 16
[  139.804002][ T2983] erofs: (device loop0): mounted with root inode @ nid 36.
[  139.810464][   T87] erofs: rq->inputsize=4096 rq->outputsize=8194
[  139.821540][   T87] erofs: rq->pageofs_in=0 rq->pageofs_out=0
[  139.824347][   T87] erofs: nrpages_in=1 nrpages_out=3
[  139.827008][   T87] erofs: ni=3 nrpages_in=1
[  139.873777][ T2983] =====================================================
[  139.881268][ T2983] BUG: KMSAN: uninit-value in ima_add_template_entry+0x626/0xa80
----------------------------------------

#syz set subsystems: erofs


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

* Re: [syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry
  2024-03-03 14:54   ` [syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry Tetsuo Handa
@ 2024-03-03 23:53     ` Gao Xiang
  2024-03-04  3:53     ` [PATCH] erofs: fix uninitialized page cache reported by KMSAN Gao Xiang
  2024-03-04  8:15     ` [syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry Roberto Sassu
  2 siblings, 0 replies; 9+ messages in thread
From: Gao Xiang @ 2024-03-03 23:53 UTC (permalink / raw)
  To: Tetsuo Handa, syzbot, syzkaller-bugs, Gao Xiang, Chao Yu, Yue Hu,
	Jeffle Xu
  Cc: linux-erofs, linux-kernel



On 2024/3/3 22:54, Tetsuo Handa wrote:
> On 2024/02/20 19:40, Roberto Sassu wrote:
>> On Mon, 2024-02-19 at 22:41 -0800, syzbot wrote:
>>> Hello,
>>>
>>> syzbot found the following issue on:
>>>
>>> HEAD commit:    4f5e5092fdbf Merge tag 'net-6.8-rc5' of git://git.kernel.o..
>>> git tree:       upstream
>>> console output: https://syzkaller.appspot.com/x/log.txt?x=135ba81c180000
>>> kernel config:  https://syzkaller.appspot.com/x/.config?x=e3dd779fba027968
>>> dashboard link: https://syzkaller.appspot.com/bug?extid=7bc44a489f0ef0670bd5
>>> compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
> 
>> I would add the VFS people in CC, in case they have some ideas.
> 
> This is an erofs bug. Since the filesystem image in the reproducer
> is crafted, decompression generates bogus result and
> z_erofs_transform_plain() misbehaves.

Yes, thanks for looking into this.  It seems it was introduced by
a new commit 1ca01520148a this cycle, let me find more clues and
make a fix for this.

Thanks,
Gao Xiang

> 
> You can obtain a single-threaded reproducer from
> https://syzkaller.appspot.com/x/repro.c?x=1256096a180000 with below diff.
> 
> ----------------------------------------
> --- old/1256096a180000.c
> +++ new/1256096a180000.c
> @@ -676,6 +676,6 @@
>     syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
>             /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
>             /*offset=*/0ul);
> -  loop();
> +  execute_one();
>     return 0;
>   }
> ----------------------------------------
> 
> With CONFIG_EROFS_FS_DEBUG=y, the reproducer hits DBG_BUGON().
> With debug printk() shown below, you can get output shown below.
> 
> ----------------------------------------
> diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
> index d4cee95af14c..f221133a0731 100644
> --- a/fs/erofs/decompressor.c
> +++ b/fs/erofs/decompressor.c
> @@ -323,7 +323,11 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
>   	unsigned int cur = 0, ni = 0, no, pi, po, insz, cnt;
>   	u8 *kin;
>   
> -	DBG_BUGON(rq->outputsize > rq->inputsize);
> +	if (rq->outputsize > rq->inputsize) {
> +		pr_err("rq->inputsize=%u rq->outputsize=%u\n", rq->inputsize, rq->outputsize);
> +		pr_err("rq->pageofs_in=%u rq->pageofs_out=%u\n", rq->pageofs_in, rq->pageofs_out);
> +		pr_err("nrpages_in=%u nrpages_out=%u\n", nrpages_in, nrpages_out);
> +	}
>   	if (rq->alg == Z_EROFS_COMPRESSION_INTERLACED) {
>   		cur = bs - (rq->pageofs_out & (bs - 1));
>   		pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK;
> @@ -352,7 +356,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
>   		do {
>   			no = (rq->pageofs_out + cur + pi) >> PAGE_SHIFT;
>   			po = (rq->pageofs_out + cur + pi) & ~PAGE_MASK;
> -			DBG_BUGON(no >= nrpages_out);
> +			if (no >= nrpages_out)
> +				pr_err("no=%u nrpages_out=%u\n", no, nrpages_out);
>   			cnt = min(insz - pi, PAGE_SIZE - po);
>   			if (rq->out[no] == rq->in[ni]) {
>   				memmove(kin + po,
> @@ -366,7 +371,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
>   		} while (pi < insz);
>   		kunmap_local(kin);
>   	}
> -	DBG_BUGON(ni > nrpages_in);
> +	if (ni > nrpages_in)
> +		pr_err("ni=%u nrpages_in=%u\n", ni, nrpages_in);
>   	return 0;
>   }
>   
> ----------------------------------------
> 
> ----------------------------------------
> [  138.991810][ T2983] loop0: detected capacity change from 0 to 16
> [  139.804002][ T2983] erofs: (device loop0): mounted with root inode @ nid 36.
> [  139.810464][   T87] erofs: rq->inputsize=4096 rq->outputsize=8194
> [  139.821540][   T87] erofs: rq->pageofs_in=0 rq->pageofs_out=0
> [  139.824347][   T87] erofs: nrpages_in=1 nrpages_out=3
> [  139.827008][   T87] erofs: ni=3 nrpages_in=1
> [  139.873777][ T2983] =====================================================
> [  139.881268][ T2983] BUG: KMSAN: uninit-value in ima_add_template_entry+0x626/0xa80
> ----------------------------------------
> 
> #syz set subsystems: erofs

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

* [PATCH] erofs: fix uninitialized page cache reported by KMSAN
  2024-03-03 14:54   ` [syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry Tetsuo Handa
  2024-03-03 23:53     ` Gao Xiang
@ 2024-03-04  3:53     ` Gao Xiang
  2024-03-04  6:04       ` Gao Xiang
                         ` (3 more replies)
  2024-03-04  8:15     ` [syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry Roberto Sassu
  2 siblings, 4 replies; 9+ messages in thread
From: Gao Xiang @ 2024-03-04  3:53 UTC (permalink / raw)
  To: linux-erofs
  Cc: syzbot+7bc44a489f0ef0670bd5, Tetsuo Handa, syzkaller-bugs, LKML,
	Roberto Sassu, linux-fsdevel, Gao Xiang

syzbot reports a KMSAN reproducer [1] which generates a crafted
filesystem image and causes IMA to read uninitialized page cache.

Later, (rq->outputsize > rq->inputsize) will be formally supported
after either large uncompressed pclusters (> block size) or big
lclusters are landed.  However, currently there is no way to generate
such filesystems by using mkfs.erofs.

Thus, let's mark this condition as unsupported for now.

[1] https://lore.kernel.org/r/0000000000002be12a0611ca7ff8@google.com

Reported-by: syzbot+7bc44a489f0ef0670bd5@syzkaller.appspotmail.com
Fixes: 1ca01520148a ("erofs: refine z_erofs_transform_plain() for sub-page block support")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/decompressor.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index d4cee95af14c..2ec9b2bb628d 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -323,7 +323,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
 	unsigned int cur = 0, ni = 0, no, pi, po, insz, cnt;
 	u8 *kin;
 
-	DBG_BUGON(rq->outputsize > rq->inputsize);
+	if (rq->outputsize > rq->inputsize)
+		return -EOPNOTSUPP;
 	if (rq->alg == Z_EROFS_COMPRESSION_INTERLACED) {
 		cur = bs - (rq->pageofs_out & (bs - 1));
 		pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK;
-- 
2.39.3


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

* Re: [PATCH] erofs: fix uninitialized page cache reported by KMSAN
  2024-03-04  3:53     ` [PATCH] erofs: fix uninitialized page cache reported by KMSAN Gao Xiang
@ 2024-03-04  6:04       ` Gao Xiang
  2024-03-04  6:51         ` [syzbot] [erofs] KMSAN: uninit-value in ima_add_template_entry syzbot
  2024-03-04 17:51       ` [PATCH] erofs: fix uninitialized page cache reported by KMSAN Sandeep Dhavale via Linux-erofs
                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Gao Xiang @ 2024-03-04  6:04 UTC (permalink / raw)
  To: linux-erofs, syzkaller-bugs
  Cc: Tetsuo Handa, syzbot+7bc44a489f0ef0670bd5, Roberto Sassu, LKML

#syz test git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test

On 2024/3/4 11:53, Gao Xiang wrote:
> syzbot reports a KMSAN reproducer [1] which generates a crafted
> filesystem image and causes IMA to read uninitialized page cache.
> 
> Later, (rq->outputsize > rq->inputsize) will be formally supported
> after either large uncompressed pclusters (> block size) or big
> lclusters are landed.  However, currently there is no way to generate
> such filesystems by using mkfs.erofs.
> 
> Thus, let's mark this condition as unsupported for now.
> 
> [1] https://lore.kernel.org/r/0000000000002be12a0611ca7ff8@google.com
> 
> Reported-by: syzbot+7bc44a489f0ef0670bd5@syzkaller.appspotmail.com
> Fixes: 1ca01520148a ("erofs: refine z_erofs_transform_plain() for sub-page block support")
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
> ---
>   fs/erofs/decompressor.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
> index d4cee95af14c..2ec9b2bb628d 100644
> --- a/fs/erofs/decompressor.c
> +++ b/fs/erofs/decompressor.c
> @@ -323,7 +323,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
>   	unsigned int cur = 0, ni = 0, no, pi, po, insz, cnt;
>   	u8 *kin;
>   
> -	DBG_BUGON(rq->outputsize > rq->inputsize);
> +	if (rq->outputsize > rq->inputsize)
> +		return -EOPNOTSUPP;
>   	if (rq->alg == Z_EROFS_COMPRESSION_INTERLACED) {
>   		cur = bs - (rq->pageofs_out & (bs - 1));
>   		pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK;

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

* Re: [syzbot] [erofs] KMSAN: uninit-value in ima_add_template_entry
  2024-03-04  6:04       ` Gao Xiang
@ 2024-03-04  6:51         ` syzbot
  0 siblings, 0 replies; 9+ messages in thread
From: syzbot @ 2024-03-04  6:51 UTC (permalink / raw)
  To: hsiangkao, linux-erofs, linux-kernel, penguin-kernel,
	roberto.sassu, syzkaller-bugs

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+7bc44a489f0ef0670bd5@syzkaller.appspotmail.com

Tested on:

commit:         4288d8d1 erofs: fix uninitialized page cache reported ..
git tree:       git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test
console output: https://syzkaller.appspot.com/x/log.txt?x=10893754180000
kernel config:  https://syzkaller.appspot.com/x/.config?x=db27810a659d0b3d
dashboard link: https://syzkaller.appspot.com/bug?extid=7bc44a489f0ef0670bd5
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

Note: no patches were applied.
Note: testing is done by a robot and is best-effort only.

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

* Re: [syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry
  2024-03-03 14:54   ` [syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry Tetsuo Handa
  2024-03-03 23:53     ` Gao Xiang
  2024-03-04  3:53     ` [PATCH] erofs: fix uninitialized page cache reported by KMSAN Gao Xiang
@ 2024-03-04  8:15     ` Roberto Sassu
  2 siblings, 0 replies; 9+ messages in thread
From: Roberto Sassu @ 2024-03-04  8:15 UTC (permalink / raw)
  To: Tetsuo Handa, syzbot, syzkaller-bugs, Gao Xiang, Chao Yu, Yue Hu,
	Jeffle Xu
  Cc: linux-integrity, linux-erofs, linux-kernel, zohar

On Sun, 2024-03-03 at 23:54 +0900, Tetsuo Handa wrote:
> On 2024/02/20 19:40, Roberto Sassu wrote:
> > On Mon, 2024-02-19 at 22:41 -0800, syzbot wrote:
> > > Hello,
> > > 
> > > syzbot found the following issue on:
> > > 
> > > HEAD commit:    4f5e5092fdbf Merge tag 'net-6.8-rc5' of git://git.kernel.o..
> > > git tree:       upstream
> > > console output: https://syzkaller.appspot.com/x/log.txt?x=135ba81c180000
> > > kernel config:  https://syzkaller.appspot.com/x/.config?x=e3dd779fba027968
> > > dashboard link: https://syzkaller.appspot.com/bug?extid=7bc44a489f0ef0670bd5
> > > compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
> 
> > I would add the VFS people in CC, in case they have some ideas.
> 
> This is an erofs bug. Since the filesystem image in the reproducer
> is crafted, decompression generates bogus result and
> z_erofs_transform_plain() misbehaves.

Thank you Tetsuo, and Gao Xiang for fixing it!

Roberto

> You can obtain a single-threaded reproducer from
> https://syzkaller.appspot.com/x/repro.c?x=1256096a180000 with below diff.
> 
> ----------------------------------------
> --- old/1256096a180000.c
> +++ new/1256096a180000.c
> @@ -676,6 +676,6 @@
>    syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
>            /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
>            /*offset=*/0ul);
> -  loop();
> +  execute_one();
>    return 0;
>  }
> ----------------------------------------
> 
> With CONFIG_EROFS_FS_DEBUG=y, the reproducer hits DBG_BUGON().
> With debug printk() shown below, you can get output shown below.
> 
> ----------------------------------------
> diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
> index d4cee95af14c..f221133a0731 100644
> --- a/fs/erofs/decompressor.c
> +++ b/fs/erofs/decompressor.c
> @@ -323,7 +323,11 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
>  	unsigned int cur = 0, ni = 0, no, pi, po, insz, cnt;
>  	u8 *kin;
>  
> -	DBG_BUGON(rq->outputsize > rq->inputsize);
> +	if (rq->outputsize > rq->inputsize) {
> +		pr_err("rq->inputsize=%u rq->outputsize=%u\n", rq->inputsize, rq->outputsize);
> +		pr_err("rq->pageofs_in=%u rq->pageofs_out=%u\n", rq->pageofs_in, rq->pageofs_out);
> +		pr_err("nrpages_in=%u nrpages_out=%u\n", nrpages_in, nrpages_out);
> +	}
>  	if (rq->alg == Z_EROFS_COMPRESSION_INTERLACED) {
>  		cur = bs - (rq->pageofs_out & (bs - 1));
>  		pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK;
> @@ -352,7 +356,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
>  		do {
>  			no = (rq->pageofs_out + cur + pi) >> PAGE_SHIFT;
>  			po = (rq->pageofs_out + cur + pi) & ~PAGE_MASK;
> -			DBG_BUGON(no >= nrpages_out);
> +			if (no >= nrpages_out)
> +				pr_err("no=%u nrpages_out=%u\n", no, nrpages_out);
>  			cnt = min(insz - pi, PAGE_SIZE - po);
>  			if (rq->out[no] == rq->in[ni]) {
>  				memmove(kin + po,
> @@ -366,7 +371,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
>  		} while (pi < insz);
>  		kunmap_local(kin);
>  	}
> -	DBG_BUGON(ni > nrpages_in);
> +	if (ni > nrpages_in)
> +		pr_err("ni=%u nrpages_in=%u\n", ni, nrpages_in);
>  	return 0;
>  }
>  
> ----------------------------------------
> 
> ----------------------------------------
> [  138.991810][ T2983] loop0: detected capacity change from 0 to 16
> [  139.804002][ T2983] erofs: (device loop0): mounted with root inode @ nid 36.
> [  139.810464][   T87] erofs: rq->inputsize=4096 rq->outputsize=8194
> [  139.821540][   T87] erofs: rq->pageofs_in=0 rq->pageofs_out=0
> [  139.824347][   T87] erofs: nrpages_in=1 nrpages_out=3
> [  139.827008][   T87] erofs: ni=3 nrpages_in=1
> [  139.873777][ T2983] =====================================================
> [  139.881268][ T2983] BUG: KMSAN: uninit-value in ima_add_template_entry+0x626/0xa80
> ----------------------------------------
> 
> #syz set subsystems: erofs


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

* Re: [PATCH] erofs: fix uninitialized page cache reported by KMSAN
  2024-03-04  3:53     ` [PATCH] erofs: fix uninitialized page cache reported by KMSAN Gao Xiang
  2024-03-04  6:04       ` Gao Xiang
@ 2024-03-04 17:51       ` Sandeep Dhavale via Linux-erofs
  2024-03-05  2:17       ` Yue Hu
  2024-03-07  1:04       ` Chao Yu
  3 siblings, 0 replies; 9+ messages in thread
From: Sandeep Dhavale via Linux-erofs @ 2024-03-04 17:51 UTC (permalink / raw)
  To: Gao Xiang
  Cc: syzbot+7bc44a489f0ef0670bd5, Tetsuo Handa, syzkaller-bugs, LKML,
	Roberto Sassu, linux-fsdevel, linux-erofs

On Sun, Mar 3, 2024 at 7:54 PM Gao Xiang <hsiangkao@linux.alibaba.com> wrote:
>
> syzbot reports a KMSAN reproducer [1] which generates a crafted
> filesystem image and causes IMA to read uninitialized page cache.
>
> Later, (rq->outputsize > rq->inputsize) will be formally supported
> after either large uncompressed pclusters (> block size) or big
> lclusters are landed.  However, currently there is no way to generate
> such filesystems by using mkfs.erofs.
>
> Thus, let's mark this condition as unsupported for now.
>
> [1] https://lore.kernel.org/r/0000000000002be12a0611ca7ff8@google.com
>
> Reported-by: syzbot+7bc44a489f0ef0670bd5@syzkaller.appspotmail.com
> Fixes: 1ca01520148a ("erofs: refine z_erofs_transform_plain() for sub-page block support")
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
> ---
>  fs/erofs/decompressor.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
> index d4cee95af14c..2ec9b2bb628d 100644
> --- a/fs/erofs/decompressor.c
> +++ b/fs/erofs/decompressor.c
> @@ -323,7 +323,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
>         unsigned int cur = 0, ni = 0, no, pi, po, insz, cnt;
>         u8 *kin;
>
> -       DBG_BUGON(rq->outputsize > rq->inputsize);
> +       if (rq->outputsize > rq->inputsize)
> +               return -EOPNOTSUPP;
>         if (rq->alg == Z_EROFS_COMPRESSION_INTERLACED) {
>                 cur = bs - (rq->pageofs_out & (bs - 1));
>                 pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK;
> --
> 2.39.3
>
LGTM.
Reviewed-by: Sandeep Dhavale <dhavale@google.com>

Thanks,
Sandeep.

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

* Re: [PATCH] erofs: fix uninitialized page cache reported by KMSAN
  2024-03-04  3:53     ` [PATCH] erofs: fix uninitialized page cache reported by KMSAN Gao Xiang
  2024-03-04  6:04       ` Gao Xiang
  2024-03-04 17:51       ` [PATCH] erofs: fix uninitialized page cache reported by KMSAN Sandeep Dhavale via Linux-erofs
@ 2024-03-05  2:17       ` Yue Hu
  2024-03-07  1:04       ` Chao Yu
  3 siblings, 0 replies; 9+ messages in thread
From: Yue Hu @ 2024-03-05  2:17 UTC (permalink / raw)
  To: Gao Xiang
  Cc: syzbot+7bc44a489f0ef0670bd5, Tetsuo Handa, syzkaller-bugs, LKML,
	Roberto Sassu, linux-fsdevel, linux-erofs

On Mon,  4 Mar 2024 11:53:39 +0800
Gao Xiang <hsiangkao@linux.alibaba.com> wrote:

> syzbot reports a KMSAN reproducer [1] which generates a crafted
> filesystem image and causes IMA to read uninitialized page cache.
> 
> Later, (rq->outputsize > rq->inputsize) will be formally supported
> after either large uncompressed pclusters (> block size) or big
> lclusters are landed.  However, currently there is no way to generate
> such filesystems by using mkfs.erofs.
> 
> Thus, let's mark this condition as unsupported for now.
> 
> [1] https://lore.kernel.org/r/0000000000002be12a0611ca7ff8@google.com
> 
> Reported-by: syzbot+7bc44a489f0ef0670bd5@syzkaller.appspotmail.com
> Fixes: 1ca01520148a ("erofs: refine z_erofs_transform_plain() for sub-page block support")
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
> ---
>  fs/erofs/decompressor.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
> index d4cee95af14c..2ec9b2bb628d 100644
> --- a/fs/erofs/decompressor.c
> +++ b/fs/erofs/decompressor.c
> @@ -323,7 +323,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
>  	unsigned int cur = 0, ni = 0, no, pi, po, insz, cnt;
>  	u8 *kin;
>  
> -	DBG_BUGON(rq->outputsize > rq->inputsize);
> +	if (rq->outputsize > rq->inputsize)
> +		return -EOPNOTSUPP;
>  	if (rq->alg == Z_EROFS_COMPRESSION_INTERLACED) {
>  		cur = bs - (rq->pageofs_out & (bs - 1));
>  		pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK;

Reviewed-by: Yue Hu <huyue2@coolpad.com>

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

* Re: [PATCH] erofs: fix uninitialized page cache reported by KMSAN
  2024-03-04  3:53     ` [PATCH] erofs: fix uninitialized page cache reported by KMSAN Gao Xiang
                         ` (2 preceding siblings ...)
  2024-03-05  2:17       ` Yue Hu
@ 2024-03-07  1:04       ` Chao Yu
  3 siblings, 0 replies; 9+ messages in thread
From: Chao Yu @ 2024-03-07  1:04 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs
  Cc: syzbot+7bc44a489f0ef0670bd5, Tetsuo Handa, syzkaller-bugs, LKML,
	Roberto Sassu, linux-fsdevel

On 2024/3/4 11:53, Gao Xiang wrote:
> syzbot reports a KMSAN reproducer [1] which generates a crafted
> filesystem image and causes IMA to read uninitialized page cache.
> 
> Later, (rq->outputsize > rq->inputsize) will be formally supported
> after either large uncompressed pclusters (> block size) or big
> lclusters are landed.  However, currently there is no way to generate
> such filesystems by using mkfs.erofs.
> 
> Thus, let's mark this condition as unsupported for now.
> 
> [1] https://lore.kernel.org/r/0000000000002be12a0611ca7ff8@google.com
> 
> Reported-by: syzbot+7bc44a489f0ef0670bd5@syzkaller.appspotmail.com
> Fixes: 1ca01520148a ("erofs: refine z_erofs_transform_plain() for sub-page block support")
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

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

end of thread, other threads:[~2024-03-07  1:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <0000000000002be12a0611ca7ff8@google.com>
     [not found] ` <40746a9ae6d2e76d748ec0bf7710bba7e49a53ac.camel@huaweicloud.com>
2024-03-03 14:54   ` [syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry Tetsuo Handa
2024-03-03 23:53     ` Gao Xiang
2024-03-04  3:53     ` [PATCH] erofs: fix uninitialized page cache reported by KMSAN Gao Xiang
2024-03-04  6:04       ` Gao Xiang
2024-03-04  6:51         ` [syzbot] [erofs] KMSAN: uninit-value in ima_add_template_entry syzbot
2024-03-04 17:51       ` [PATCH] erofs: fix uninitialized page cache reported by KMSAN Sandeep Dhavale via Linux-erofs
2024-03-05  2:17       ` Yue Hu
2024-03-07  1:04       ` Chao Yu
2024-03-04  8:15     ` [syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry Roberto Sassu

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