mm/shmem: fix uninitialized folio in shmem_symlink
Subsystems (2)
PATCH 1/1 mm/shmem: fix uninitialized folio in shmem_symlink
From: Barry Song <[email protected]>
Uninitialized folio allocated in shmem_symlink() may be accessed during swap-out, causing KMSAN BUG:
BUG: KMSAN: uninit-value in is_folio_zero_filled mm/page_io.c:188 [inline] BUG: KMSAN: uninit-value in swap_writeout+0x468/0x1390 mm/page_io.c:263 is_folio_zero_filled mm/page_io.c:188 [inline] swap_writeout+0x468/0x1390 mm/page_io.c:263 shmem_writeout+0x1abb/0x1f60 mm/shmem.c:1662 writeout mm/vmscan.c:649 [inline] pageout mm/vmscan.c:698 [inline] shrink_folio_list+0x5920/0x7fc0 mm/vmscan.c:1418 evict_folios+0x999d/0xbf30 mm/vmscan.c:4711 try_to_shrink_lruvec+0x12b6/0x17e0 mm/vmscan.c:4874 lru_gen_shrink_lruvec mm/vmscan.c:5023 [inline] shrink_lruvec+0x46f/0x4f10 mm/vmscan.c:5784 shrink_node_memcgs mm/vmscan.c:6020 [inline]
This patch clears the remaining part to zero for the portion not covered by memcpy from symname.
--- mm/shmem.c | 1 + 1 file changed, 1 insertion(+)
mm/shmem.c +1 -0
@@ -4131,6 +4131,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, goto out_remove_offset; inode->i_op = &shmem_symlink_inode_operations;memcpy (folio_address (folio), symname, len); +folio_zero_range (folio, len,folio_size (folio) - len);folio_mark_uptodate (folio);folio_mark_dirty (folio);folio_unlock (folio);
Signature · 1 line
2.43.0
Quoted 4 lines · Barry Song
From: Barry Song <[email protected]>
Uninitialized folio allocated in
shmem_symlink()may be accessed during swap-out, causing KMSAN BUG:
This would be an unfortunate way to fix it. The vast majority of symlinks are short, and we'll never access past the \0 in normal operation, so we'll be dirtying a lot of cachelines essentially to (1) shut up an automated tool and (2) optimise a corner case.
How about this instead which delays zeroing to swapout?
mm/shmem.c +8 -0
@@ -1636,6 +1636,13 @@ int shmem_writeout(struct folio *folio, struct swap_iocb **plug,folio_mark_uptodate (folio); } +/* Zero out symlink tails to help with compression */ +if (folio_test_owner_2 (folio)) { +struct inode *inode = folio->mapping->host; +folio_zero_segment (folio, inode->i_size,folio_size (folio)); +folio_clear_owner_2 (folio); + } +if (!folio_alloc_swap (folio)) {bool first_swapped =shmem_recalc_inode (inode,0 , nr_pages);int error;
@@ -4133,6 +4140,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,memcpy (folio_address (folio), symname, len);folio_mark_uptodate (folio);folio_mark_dirty (folio); +folio_set_owner_2 (folio);folio_unlock (folio);folio_put (folio); }
Quoted 7 lines · Matthew Wilcox
Quoted 4 lines · Barry Song
From: Barry Song <[email protected]>
Uninitialized folio allocated in
shmem_symlink()may be accessed during swap-out, causing KMSAN BUG:
Quoted 6 lines
This would be an unfortunate way to fix it. The vast majority of symlinks are short, and we'll never access past the \0 in normal operation, so we'll be dirtying a lot of cachelines essentially to (1) shut up an automated tool and (2) optimise a corner case.
How about this instead which delays zeroing to swapout?
Matthew, thank you very much for your review, even during Christmas. I would like to wish you a happy holiday!
I am not quite sure, as shm symlinks do not seem very common. Since allocating a folio requires a symname longer than 128 bytes (where 128 == SHORT_SYMLINK_LEN), such cases appear even rarer.
BTW, do we need to migrate the owner_2 flag in folio_migrate_flags()? If so, I am not quite sure it is worth changing the hotpath to accommodate this.
Quoted 20 lines
mm/shmem.c +7
-0@@ -1636,6 +1636,13 @@ int shmem_writeout(struct folio *folio, struct swap_iocb **plug,folio_mark_uptodate (folio); } +/* Zero out symlink tails to help with compression */ +if (folio_test_owner_2 (folio)) { +struct inode *inode = folio->mapping->host; +folio_zero_segment (folio, inode->i_size,folio_size (folio)); +folio_clear_owner_2 (folio); + } +if (!folio_alloc_swap (folio)) {bool first_swapped =shmem_recalc_inode (inode,0 , nr_pages);int error;
mm/shmem.c static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, · line 4146
Quoted 7 lines
mm/shmem.c +1
-0@@ -4133,6 +4140,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,memcpy (folio_address (folio), symname, len);folio_mark_uptodate (folio);folio_mark_dirty (folio); +folio_set_owner_2 (folio);folio_unlock (folio);folio_put (folio); }
Thanks
Barry
Baolin Wang
reviewerQuoted 18 lines · Barry Song
Quoted 7 lines · Matthew Wilcox
Quoted 4 lines · Barry Song
From: Barry Song <[email protected]>
Uninitialized folio allocated in
shmem_symlink()may be accessed during swap-out, causing KMSAN BUG:Quoted 6 lines
This would be an unfortunate way to fix it. The vast majority of symlinks are short, and we'll never access past the \0 in normal operation, so we'll be dirtying a lot of cachelines essentially to (1) shut up an automated tool and (2) optimise a corner case.
How about this instead which delays zeroing to swapout?
Matthew, thank you very much for your review, even during Christmas. I would like to wish you a happy holiday!
Quoted 7 lines
I am not quite sure, as shm symlinks do not seem very common. Since allocating a folio requires a symname longer than 128 bytes (where 128 ==
SHORT_SYMLINK_LEN), such cases appear even rarer.BTW, do we need to migrate the
owner_2flag infolio_migrate_flags()? If so, I am not quite sure it is worth changing the hotpath to accommodate this.
+1. At least for me, using the 'PG_owner_2' flag alone to mark this uncommon case doesn't seem quite worthwhile.
Quoted 29 lines
Quoted 19 lines
mm/shmem.c +7
-0@@ -1636,6 +1636,13 @@ int shmem_writeout(struct folio *folio, struct swap_iocb **plug,folio_mark_uptodate (folio); } +/* Zero out symlink tails to help with compression */ +if (folio_test_owner_2 (folio)) { +struct inode *inode = folio->mapping->host; +folio_zero_segment (folio, inode->i_size,folio_size (folio)); +folio_clear_owner_2 (folio); + } +if (!folio_alloc_swap (folio)) {bool first_swapped =shmem_recalc_inode (inode,0 , nr_pages);int error;mm/shmem.c static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, · line 4146
Quoted 7 lines
mm/shmem.c +1
-0@@ -4133,6 +4140,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,memcpy (folio_address (folio), symname, len);folio_mark_uptodate (folio);folio_mark_dirty (folio); +folio_set_owner_2 (folio);folio_unlock (folio);folio_put (folio); }Thanks
Barry
Quoted 25 lines · Baolin Wang
Quoted 22 lines · Barry Song
Quoted 7 lines · Matthew Wilcox
Quoted 4 lines · Barry Song
From: Barry Song <[email protected]>
Uninitialized folio allocated in
shmem_symlink()may be accessed during swap-out, causing KMSAN BUG:Quoted 6 lines
This would be an unfortunate way to fix it. The vast majority of symlinks are short, and we'll never access past the \0 in normal operation, so we'll be dirtying a lot of cachelines essentially to (1) shut up an automated tool and (2) optimise a corner case.
How about this instead which delays zeroing to swapout?
Matthew, thank you very much for your review, even during Christmas. I would like to wish you a happy holiday!
I am not quite sure, as shm symlinks do not seem very common. Since allocating a folio requires a symname longer than 128 bytes (where 128 ==
SHORT_SYMLINK_LEN), such cases appear even rarer.
Quoted 7 lines
Quoted 3 lines
BTW, do we need to migrate the
owner_2flag infolio_migrate_flags()? If so, I am not quite sure it is worth changing the hotpath to accommodate this.+1. At least for me, using the '
PG_owner_2' flag alone to mark this uncommon case doesn't seem quite worthwhile.
Also JFYI the post-eof swapout zeroing work (still pending) looks to me like it would cover the swapout time case [1]. That's just if you wanted to go that route here; creation time zeroing for the large symlink case seems reasonable enough to me as well.
Brian
[1] https://lore.kernel.org/linux-mm/[email protected]/
Quoted 31 lines
Quoted 29 lines
Quoted 19 lines
mm/shmem.c +7
-0@@ -1636,6 +1636,13 @@ int shmem_writeout(struct folio *folio, struct swap_iocb **plug,folio_mark_uptodate (folio); } +/* Zero out symlink tails to help with compression */ +if (folio_test_owner_2 (folio)) { +struct inode *inode = folio->mapping->host; +folio_zero_segment (folio, inode->i_size,folio_size (folio)); +folio_clear_owner_2 (folio); + } +if (!folio_alloc_swap (folio)) {bool first_swapped =shmem_recalc_inode (inode,0 , nr_pages);int error;mm/shmem.c static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, · line 4146
Quoted 7 lines
mm/shmem.c +1
-0@@ -4133,6 +4140,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,memcpy (folio_address (folio), symname, len);folio_mark_uptodate (folio);folio_mark_dirty (folio); +folio_set_owner_2 (folio);folio_unlock (folio);folio_put (folio); }Thanks
Barry
Quoted 4 lines · Brian Foster
Also JFYI the post-eof swapout zeroing work (still pending) looks to me like it would cover the swapout time case [1]. That's just if you wanted to go that route here; creation time zeroing for the large symlink case seems reasonable enough to me as well.
I think we should merge your patch series instead.
Baolin Wang
reviewerQuoted 30 lines · Brian Foster
Quoted 29 lines · Baolin Wang
Quoted 25 lines · Barry Song
Quoted 7 lines · Matthew Wilcox
Quoted 4 lines · Barry Song
From: Barry Song <[email protected]>
Uninitialized folio allocated in
shmem_symlink()may be accessed during swap-out, causing KMSAN BUG:Quoted 6 lines
This would be an unfortunate way to fix it. The vast majority of symlinks are short, and we'll never access past the \0 in normal operation, so we'll be dirtying a lot of cachelines essentially to (1) shut up an automated tool and (2) optimise a corner case.
How about this instead which delays zeroing to swapout?
Matthew, thank you very much for your review, even during Christmas. I would like to wish you a happy holiday!
I am not quite sure, as shm symlinks do not seem very common. Since allocating a folio requires a symname longer than 128 bytes (where 128 ==
SHORT_SYMLINK_LEN), such cases appear even rarer.BTW, do we need to migrate the
owner_2flag infolio_migrate_flags()? If so, I am not quite sure it is worth changing the hotpath to accommodate this.
Quoted 8 lines
Quoted 3 lines
+1. At least for me, using the '
PG_owner_2' flag alone to mark this uncommon case doesn't seem quite worthwhile.Also JFYI the post-eof swapout zeroing work (still pending) looks to me like it would cover the swapout time case [1]. That's just if you wanted to go that route here; creation time zeroing for the large symlink case seems reasonable enough to me as well.
IMHO, your post-eof zeroing work is intended to zero !uptodate or beyond EOF folios before swap-out, however, the symlink folio is uptodate and not beyond the EOF. I am not sure if it will make your code more complicated when you want to cover this symlink case.
Why I prefer Barry's fix: First, the symlink folio is marked Uptodate after copying the symlink name, but the whole folio hasn’t been initialized, which seems unreasonable to me. Second, as I said before, using the 'PG_owner_2' flag to mark this uncommon case doesn’t seem worthwhile. Currently, IIUC the 'PG_owner_2' is only used by btrfs; if we ever want to remove the 'PG_owner_2', this uncommon symlink case shouldn’t block its removal.
BTW, as I said before, I've reviewed and tested your post-eof work[1]. Maybe you could resend the patch set so that Hugh can take a look when he has time.
Quoted 33 lines
[1] https://lore.kernel.org/linux-mm/[email protected]/
Quoted 31 lines
Quoted 29 lines
Quoted 19 lines
mm/shmem.c +7
-0@@ -1636,6 +1636,13 @@ int shmem_writeout(struct folio *folio, struct swap_iocb **plug,folio_mark_uptodate (folio); } +/* Zero out symlink tails to help with compression */ +if (folio_test_owner_2 (folio)) { +struct inode *inode = folio->mapping->host; +folio_zero_segment (folio, inode->i_size,folio_size (folio)); +folio_clear_owner_2 (folio); + } +if (!folio_alloc_swap (folio)) {bool first_swapped =shmem_recalc_inode (inode,0 , nr_pages);int error;mm/shmem.c static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, · line 4146
Quoted 7 lines
mm/shmem.c +1
-0@@ -4133,6 +4140,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,memcpy (folio_address (folio), symname, len);folio_mark_uptodate (folio);folio_mark_dirty (folio); +folio_set_owner_2 (folio);folio_unlock (folio);folio_put (folio); }Thanks
Barry
Quoted 42 lines · Baolin Wang
Quoted 30 lines · Brian Foster
Quoted 29 lines · Baolin Wang
Quoted 25 lines · Barry Song
Quoted 7 lines · Matthew Wilcox
Quoted 4 lines · Barry Song
From: Barry Song <[email protected]>
Uninitialized folio allocated in
shmem_symlink()may be accessed during swap-out, causing KMSAN BUG:Quoted 6 lines
This would be an unfortunate way to fix it. The vast majority of symlinks are short, and we'll never access past the \0 in normal operation, so we'll be dirtying a lot of cachelines essentially to (1) shut up an automated tool and (2) optimise a corner case.
How about this instead which delays zeroing to swapout?
Matthew, thank you very much for your review, even during Christmas. I would like to wish you a happy holiday!
I am not quite sure, as shm symlinks do not seem very common. Since allocating a folio requires a symname longer than 128 bytes (where 128 ==
SHORT_SYMLINK_LEN), such cases appear even rarer.BTW, do we need to migrate the
owner_2flag infolio_migrate_flags()? If so, I am not quite sure it is worth changing the hotpath to accommodate this.Quoted 8 lines
Quoted 3 lines
+1. At least for me, using the '
PG_owner_2' flag alone to mark this uncommon case doesn't seem quite worthwhile.Also JFYI the post-eof swapout zeroing work (still pending) looks to me like it would cover the swapout time case [1]. That's just if you wanted to go that route here; creation time zeroing for the large symlink case seems reasonable enough to me as well.
Quoted 5 lines
IMHO, your post-eof zeroing work is intended to zero !uptodate or beyond EOF folios before swap-out, however, the symlink folio is uptodate and not beyond the EOF. I am not sure if it will make your code more complicated when you want to cover this symlink case.
It already handles this particular case. The primary intent is to zero all post-eof ranges that can be written out before that write out happens. I.e., if you take a look at shmem_writeout(), if the folio happens to straddle i_size we zero from i_size to the end of the folio.
Quoted 7 lines
Why I prefer Barry's fix: First, the symlink folio is marked Uptodate after copying the symlink name, but the whole folio hasn’t been initialized, which seems unreasonable to me. Second, as I said before, using the '
PG_owner_2' flag to mark this uncommon case doesn’t seem worthwhile. Currently, IIUC the 'PG_owner_2' is only used by btrfs; if we ever want to remove the 'PG_owner_2', this uncommon symlink case shouldn’t block its removal.
I think we're talking past eachother a bit here. ;) I'm pointing out that outstanding work already covers writeout time zeroing so as to avoid duplicate effort if this was trending that way. IOW, I think there's no reason to consider the page flag thing, it's more of a question of do you want the zeroing at creation time or not..
I again don't have a strong opinion on this, but I think I can see justification either way. If the focus is a KMSAN splat at writeout time, then it makes some sense to address it in that slower/less likely path.
That said, if we step back and consider that if this were a buffered write we'd tail zero the folio at write time before marking it uptodate, this seems like more broadly consistent behavior with other fs' and operations. This would be analogous to say XFS allocating a zeroed metadata buffer on symlink creation to ensure the underlying block is tail zeroed before it is eventually written to disk.
So to your point, maybe the most appropriate thing to do is cover zeroing in both places..
Quoted 4 lines
BTW, as I said before, I've reviewed and tested your post-eof work[1]. Maybe you could resend the patch set so that Hugh can take a look when he has time.
Yeah.. I know Hugh is busy and that isn't the highest priority series. I'm just catching back up from time off myself so I can give it more time before I repost it or anything.
Brian
Quoted 34 lines
Quoted 33 lines
[1] https://lore.kernel.org/linux-mm/[email protected]/
Quoted 31 lines
Quoted 29 lines
Quoted 19 lines
mm/shmem.c +7
-0@@ -1636,6 +1636,13 @@ int shmem_writeout(struct folio *folio, struct swap_iocb **plug,folio_mark_uptodate (folio); } +/* Zero out symlink tails to help with compression */ +if (folio_test_owner_2 (folio)) { +struct inode *inode = folio->mapping->host; +folio_zero_segment (folio, inode->i_size,folio_size (folio)); +folio_clear_owner_2 (folio); + } +if (!folio_alloc_swap (folio)) {bool first_swapped =shmem_recalc_inode (inode,0 , nr_pages);int error;mm/shmem.c static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, · line 4146
Quoted 7 lines
mm/shmem.c +1
-0@@ -4133,6 +4140,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,memcpy (folio_address (folio), symname, len);folio_mark_uptodate (folio);folio_mark_dirty (folio); +folio_set_owner_2 (folio);folio_unlock (folio);folio_put (folio); }Thanks
Barry
Baolin Wang
reviewerQuoted 49 lines · Brian Foster
Quoted 42 lines · Baolin Wang
Quoted 30 lines · Brian Foster
Quoted 29 lines · Baolin Wang
Quoted 25 lines · Barry Song
Quoted 7 lines · Matthew Wilcox
Quoted 4 lines · Barry Song
From: Barry Song <[email protected]>
Uninitialized folio allocated in
shmem_symlink()may be accessed during swap-out, causing KMSAN BUG:Quoted 6 lines
This would be an unfortunate way to fix it. The vast majority of symlinks are short, and we'll never access past the \0 in normal operation, so we'll be dirtying a lot of cachelines essentially to (1) shut up an automated tool and (2) optimise a corner case.
How about this instead which delays zeroing to swapout?
Matthew, thank you very much for your review, even during Christmas. I would like to wish you a happy holiday!
I am not quite sure, as shm symlinks do not seem very common. Since allocating a folio requires a symname longer than 128 bytes (where 128 ==
SHORT_SYMLINK_LEN), such cases appear even rarer.BTW, do we need to migrate the
owner_2flag infolio_migrate_flags()? If so, I am not quite sure it is worth changing the hotpath to accommodate this.Quoted 8 lines
Quoted 3 lines
+1. At least for me, using the '
PG_owner_2' flag alone to mark this uncommon case doesn't seem quite worthwhile.Also JFYI the post-eof swapout zeroing work (still pending) looks to me like it would cover the swapout time case [1]. That's just if you wanted to go that route here; creation time zeroing for the large symlink case seems reasonable enough to me as well.
Quoted 5 lines
IMHO, your post-eof zeroing work is intended to zero !uptodate or beyond EOF folios before swap-out, however, the symlink folio is uptodate and not beyond the EOF. I am not sure if it will make your code more complicated when you want to cover this symlink case.
Quoted 4 lines
It already handles this particular case. The primary intent is to zero all post-eof ranges that can be written out before that write out happens. I.e., if you take a look at
shmem_writeout(), if the folio happens to straddlei_sizewe zero fromi_sizeto the end of the folio.
Ah, yes. I’ve rechecked your patch set, and you’re right.
Quoted 8 lines
Quoted 7 lines
Why I prefer Barry's fix: First, the symlink folio is marked Uptodate after copying the symlink name, but the whole folio hasn’t been initialized, which seems unreasonable to me. Second, as I said before, using the '
PG_owner_2' flag to mark this uncommon case doesn’t seem worthwhile. Currently, IIUC the 'PG_owner_2' is only used by btrfs; if we ever want to remove the 'PG_owner_2', this uncommon symlink case shouldn’t block its removal.
Quoted 5 lines
I think we're talking past eachother a bit here. ;) I'm pointing out that outstanding work already covers writeout time zeroing so as to avoid duplicate effort if this was trending that way. IOW, I think there's no reason to consider the page flag thing, it's more of a question of do you want the zeroing at creation time or not..
Yes. It is very strange that a folio is marked uptodate but is not fully initialized.
Quoted 12 lines
I again don't have a strong opinion on this, but I think I can see justification either way. If the focus is a KMSAN splat at writeout time, then it makes some sense to address it in that slower/less likely path.
That said, if we step back and consider that if this were a buffered write we'd tail zero the folio at write time before marking it uptodate, this seems like more broadly consistent behavior with other fs' and operations. This would be analogous to say XFS allocating a zeroed metadata buffer on symlink creation to ensure the underlying block is tail zeroed before it is eventually written to disk.
Quoted 2 lines
So to your point, maybe the most appropriate thing to do is cover zeroing in both places..
Agree.
Quoted 8 lines
Quoted 4 lines
BTW, as I said before, I've reviewed and tested your post-eof work[1]. Maybe you could resend the patch set so that Hugh can take a look when he has time.
Yeah.. I know Hugh is busy and that isn't the highest priority series. I'm just catching back up from time off myself so I can give it more time before I repost it or anything.
Sure.
Quoted 6 lines · Baolin Wang
Why I prefer Barry's fix: First, the symlink folio is marked Uptodate after copying the symlink name, but the whole folio hasn’t been initialized, which seems unreasonable to me. Second, as I said before, using the '
PG_owner_2' flag to mark this uncommon case doesn’t seem worthwhile. Currently, IIUC the 'PG_owner_2' is only used by btrfs; if we ever want to remove the 'PG_owner_2', this uncommon symlink case shouldn’t block its removal.
PG_owner_2 is aliased with PG_mappedtodisk [1], so it's used by every filesystem which uses buffer_heads (whether mentioned in that filesystem or not). btrfs was switched from using private_2 to using owner_2 a little over a year ago. PG_owner_2 is not on the list of flags to be removed; that's PG_private, PG_private_2 and PG_reserved.
[1] include/linux/page-flags.h: PG_mappedtodisk = PG_owner_2,
Baolin Wang
reviewerQuoted 8 lines · Matthew Wilcox
Quoted 6 lines · Baolin Wang
Why I prefer Barry's fix: First, the symlink folio is marked Uptodate after copying the symlink name, but the whole folio hasn’t been initialized, which seems unreasonable to me. Second, as I said before, using the '
PG_owner_2' flag to mark this uncommon case doesn’t seem worthwhile. Currently, IIUC the 'PG_owner_2' is only used by btrfs; if we ever want to remove the 'PG_owner_2', this uncommon symlink case shouldn’t block its removal.
Quoted 5 lines
PG_owner_2is aliased withPG_mappedtodisk[1], so it's used by every filesystem which usesbuffer_heads(whether mentioned in that filesystem or not). btrfs was switched from usingprivate_2to usingowner_2a little over a year ago.PG_owner_2is not on the list of flags to be removed; that'sPG_private,PG_private_2andPG_reserved.
OK. Thanks for the explanation. I understand the plan.
Quoted 13 lines · Barry Song
Quoted 12 lines · Matthew Wilcox
Quoted 4 lines · Barry Song
From: Barry Song <[email protected]>
Uninitialized folio allocated in
shmem_symlink()may be accessed during swap-out, causing KMSAN BUG:This would be an unfortunate way to fix it. The vast majority of symlinks are short, and we'll never access past the \0 in normal operation, so we'll be dirtying a lot of cachelines essentially to (1) shut up an automated tool and (2) optimise a corner case.
Quoted 4 lines
Quoted 1 line
How about this instead which delays zeroing to swapout?
Matthew, thank you very much for your review, even during Christmas. I would like to wish you a happy holiday!
Heh, thanks. My mailserver is actually in a different timezone from me, so it was still the 24th when I sent it ;-)
Quoted 3 lines
I am not quite sure, as shm symlinks do not seem very common. Since allocating a folio requires a symname longer than 128 bytes (where 128 ==
SHORT_SYMLINK_LEN), such cases appear even rarer.
Fair enough. I hadn't noticed the SHORT_SYMLINK_LEN case when I wrote this. That does change things somewhat, but still for a 160 byte symlink, we have 5 cachelines of data and 59 cachelines of zeroes.
Quoted 3 lines
BTW, do we need to migrate the
owner_2flag infolio_migrate_flags()? If so, I am not quite sure it is worth changing the hotpath to accommodate this.
It already happens, it's just camouflaged. owner_2 is the same bit as mappedtodisk.
Quoted 22 lines · Barry Song
From: Barry Song <[email protected]>
Uninitialized folio allocated in
shmem_symlink()may be accessed during swap-out, causing KMSAN BUG:BUG: KMSAN: uninit-value in is_folio_zero_filled mm/page_io.c:188 [inline] BUG: KMSAN: uninit-value in swap_writeout+0x468/0x1390 mm/page_io.c:263 is_folio_zero_filled mm/page_io.c:188 [inline] swap_writeout+0x468/0x1390 mm/page_io.c:263 shmem_writeout+0x1abb/0x1f60 mm/shmem.c:1662 writeout mm/vmscan.c:649 [inline] pageout mm/vmscan.c:698 [inline] shrink_folio_list+0x5920/0x7fc0 mm/vmscan.c:1418 evict_folios+0x999d/0xbf30 mm/vmscan.c:4711 try_to_shrink_lruvec+0x12b6/0x17e0 mm/vmscan.c:4874 lru_gen_shrink_lruvec mm/vmscan.c:5023 [inline] shrink_lruvec+0x46f/0x4f10 mm/vmscan.c:5784 shrink_node_memcgs mm/vmscan.c:6020 [inline]This patch clears the remaining part to zero for the portion not covered by memcpy from symname.
Quoted 6 lines
Cc Hugh Dickins <[email protected]>Cc Baolin Wang <[email protected]>Reported-by [email protected]Signed-off-by Barry Song <[email protected]>---
LGTM. Thanks.
Quoted 15 lines
mm/shmem.c | 1 + 1 file changed, 1 insertion(+)mm/shmem.c +1
-0@@ -4131,6 +4131,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, goto out_remove_offset; inode->i_op = &shmem_symlink_inode_operations;memcpy (folio_address (folio), symname, len); +folio_zero_range (folio, len,folio_size (folio) - len);folio_mark_uptodate (folio);folio_mark_dirty (folio);folio_unlock (folio);