linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* kmap + memmove
@ 2024-05-05 12:25 Matthew Wilcox
  2024-05-05 13:01 ` Julia Lawall
  2024-05-06  4:14 ` Matthew Wilcox
  0 siblings, 2 replies; 10+ messages in thread
From: Matthew Wilcox @ 2024-05-05 12:25 UTC (permalink / raw)
  To: Dan Carpenter, Julia Lawall
  Cc: Fabio M. De Francesco, Ira Weiny, Viacheslav Dubeyko,
	Andrew Morton, Bart Van Assche, Kees Cook, linux-fsdevel

Here's a fun bug that's not obvious:

hfs_bnode_move:
                                dst_ptr = kmap_local_page(*dst_page);
                                src_ptr = kmap_local_page(*src_page);
                                memmove(dst_ptr, src_ptr, src);

If both of the pointers are guaranteed to come from diffeerent calls to
kmap_local(), memmove() is probably not going to do what you want.
Worth a smatch or coccinelle rule?

The only time that memmove() is going to do something different from
memcpy() is when src and dst overlap.  But if src and dst both come
from kmap_local(), they're guaranteed to not overlap.  Even if dst_page
and src_page were the same.

Which means the conversion in 6c3014a67a44 was buggy.  Calling kmap()
for the same page twice gives you the same address.  Calling kmap_local()
for the same page twice gives you two different addresses.

Fabio, how many other times did you create this same bug?  Ira, I'm
surprised you didn't catch this one; you created the same bug in
memmove_page() which I got Fabio to delete in 9384d79249d0.

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

end of thread, other threads:[~2024-08-22 18:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-05 12:25 kmap + memmove Matthew Wilcox
2024-05-05 13:01 ` Julia Lawall
2024-05-06  3:40   ` Ira Weiny
2024-05-06  5:15     ` Julia Lawall
2024-05-06  5:48     ` Julia Lawall
2024-05-06  5:50       ` Julia Lawall
2024-05-06  3:47   ` Matthew Wilcox
2024-05-06  4:14 ` Matthew Wilcox
2024-05-24 19:35   ` Matthew Wilcox
2024-08-22 18:54     ` Matthew Wilcox

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).