linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG] arm64: an infinite loop in generic_perform_write()
@ 2021-06-23  2:39 Chen Huang
  2021-06-23  2:50 ` Al Viro
  2021-06-23 13:22 ` Mark Rutland
  0 siblings, 2 replies; 31+ messages in thread
From: Chen Huang @ 2021-06-23  2:39 UTC (permalink / raw)
  To: Andrew Morton, Stephen Rothwell, Matthew Wilcox (Oracle),
	Al Viro, Randy Dunlap, Catalin Marinas, Will Deacon
  Cc: Linux ARM, linux-mm, open list

When we access a device memory in userspace, then perform an unaligned write to a file.
For example, we register a uio device and mmap the device, then perform an write to a
file, like that:

	device_addr = mmap(device_fd);
	write(file_fd, device_addr + unaligned_num, size);
	
We found that the infinite loop happened in generic_perform_write function:

again:
	copied = copy_page_from_iter_atomic(); //copied = 0
	status = ops->write_end(); //status = 0
	if (status == 0)
		goto again;

In copy_page_from_iter_atomic, the copyin() function finally call
__arch_copy_from_user which create an exception table entry for 'insn'.
Then when kernel handles the alignment_fault, it will not panic. As the
arm64 memory model spec said, when the address is not a multiple of the
element size, the access is unaligned. Unaligned accesses are allowed to
addresses marked as Normal, but not to Device regions. An unaligned access
to a Device region will trigger an exception (alignment fault).
	
do_alignment_fault
    do_bad_area
	__do_kernel_fault
           fixup_exception

But that fixup cann't handle the unaligned copy, so the
copy_page_from_iter_atomic returns 0 and traps in loop.

Reported-by: Chen Huang <chenhuang5@huawei.com>

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

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

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-23  2:39 [BUG] arm64: an infinite loop in generic_perform_write() Chen Huang
2021-06-23  2:50 ` Al Viro
2021-06-23  3:24   ` Xiaoming Ni
2021-06-23  4:27     ` Al Viro
2021-06-23  9:32       ` Catalin Marinas
2021-06-23 11:51         ` Matthew Wilcox
2021-06-23 13:04         ` Al Viro
2021-06-23 13:22 ` Mark Rutland
2021-06-24  3:10   ` Chen Huang
2021-06-24  3:24     ` Matthew Wilcox
2021-06-24  3:52       ` Chen Huang
2021-06-24  7:04       ` Christoph Hellwig
2021-06-24 11:15         ` Matthew Wilcox
2021-06-24 13:22           ` Robin Murphy
2021-06-24 16:27             ` Al Viro
2021-06-24 16:38               ` Robin Murphy
2021-06-24 16:39                 ` Al Viro
2021-06-24 17:24                   ` Robin Murphy
2021-06-24 18:55               ` Catalin Marinas
2021-06-24 20:36                 ` Robin Murphy
2021-06-25 10:39                   ` Catalin Marinas
2021-06-28 16:22                     ` Robin Murphy
2021-06-29  8:30                       ` Catalin Marinas
2021-06-29 10:01                         ` Robin Murphy
2021-07-06 17:50                       ` Catalin Marinas
2021-07-06 19:15                         ` Robin Murphy
2021-07-07  9:55                           ` David Laight
2021-07-07 11:04                             ` Robin Murphy
2021-07-07 12:50                           ` Catalin Marinas
2021-06-24 15:09           ` Catalin Marinas
2021-06-24 16:17             ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).