All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next 1/1] iomap: Fix a false positive of UBSAN in iomap_seek_data()
@ 2021-07-02  9:21 Zhen Lei
  2021-07-02  9:34 ` Christoph Hellwig
  2021-07-02 19:56 ` Matthew Wilcox
  0 siblings, 2 replies; 11+ messages in thread
From: Zhen Lei @ 2021-07-02  9:21 UTC (permalink / raw)
  To: Christoph Hellwig, Darrick J . Wong, linux-xfs, linux-fsdevel,
	linux-kernel
  Cc: Zhen Lei

Move the evaluation expression "size - offset" after the "if (offset < 0)"
judgment statement to eliminate a false positive produced by the UBSAN.

No functional changes.

==========================================================================
UBSAN: Undefined behaviour in fs/iomap.c:1435:9
signed integer overflow:
0 - -9223372036854775808 cannot be represented in type 'long long int'
CPU: 1 PID: 462 Comm: syz-executor852 Tainted: G ---------r-  - 4.18.0+ #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ...
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0xca/0x13e lib/dump_stack.c:113
 ubsan_epilogue+0xe/0x81 lib/ubsan.c:159
 handle_overflow+0x193/0x1e2 lib/ubsan.c:190
 iomap_seek_data+0x128/0x140 fs/iomap.c:1435
 ext4_llseek+0x1e3/0x290 fs/ext4/file.c:494
 vfs_llseek fs/read_write.c:300 [inline]
 ksys_lseek+0xe9/0x160 fs/read_write.c:313
 do_syscall_64+0xca/0x5b0 arch/x86/entry/common.c:293
 entry_SYSCALL_64_after_hwframe+0x6a/0xdf
==========================================================================

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 fs/iomap/seek.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/iomap/seek.c b/fs/iomap/seek.c
index dab1b02eba5b..778e3e84c95e 100644
--- a/fs/iomap/seek.c
+++ b/fs/iomap/seek.c
@@ -83,13 +83,14 @@ loff_t
 iomap_seek_data(struct inode *inode, loff_t offset, const struct iomap_ops *ops)
 {
 	loff_t size = i_size_read(inode);
-	loff_t length = size - offset;
+	loff_t length;
 	loff_t ret;
 
 	/* Nothing to be found before or beyond the end of the file. */
 	if (offset < 0 || offset >= size)
 		return -ENXIO;
 
+	length = size - offset;
 	while (length > 0) {
 		ret = iomap_apply(inode, offset, length, IOMAP_REPORT, ops,
 				  &offset, iomap_seek_data_actor);
-- 
2.25.1



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

end of thread, other threads:[~2021-07-06 12:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-02  9:21 [PATCH -next 1/1] iomap: Fix a false positive of UBSAN in iomap_seek_data() Zhen Lei
2021-07-02  9:34 ` Christoph Hellwig
2021-07-02 11:50   ` Leizhen (ThunderTown)
2021-07-05  3:29     ` Leizhen (ThunderTown)
2021-07-05  3:43       ` Matthew Wilcox
2021-07-05  4:05         ` Leizhen (ThunderTown)
2021-07-04 13:51   ` Matthew Wilcox
2021-07-02 19:56 ` Matthew Wilcox
2021-07-05  3:35   ` Leizhen (ThunderTown)
2021-07-06 11:08     ` Matthew Wilcox
2021-07-06 11:59       ` Matthew Wilcox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.