Commit 0766ec8
namei: Fix use after free in kern_path_locked
In 0ee50b4 ("namei: change filename_parentat() calling
conventions"), filename_parentat() was made to always call putname() on
the filename before returning, and kern_path_locked() was migrated to
this calling convention. However, kern_path_locked() uses the "last"
parameter to lookup and potentially create a new dentry. The last
parameter contains the last component of the path and points within the
filename, which was recently freed at the end of filename_parentat().
Thus, when kern_path_locked() calls __lookup_hash(), it is using the
filename after it has already been freed.
In other words, these calling conventions had been wrong for the
only remaining caller of filename_parentat(). Everything else
is using __filename_parentat(), which does not drop the reference;
so should kern_path_locked().
Switch kern_path_locked() to use of __filename_parentat() and move
getting/dropping struct filename into wrapper. Remove filename_parentat(),
now that we have no remaining callers.
Fixes: 0ee50b4 ("namei: change filename_parentat() calling conventions")
Link: https://lore.kernel.org/linux-fsdevel/YS9D4AlEsaCxLFV0@infradead.org/
Link: https://lore.kernel.org/linux-fsdevel/YS+csMTV2tTXKg3s@zeniv-ca.linux.org.uk/
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Reported-by: syzbot+fb0d60a179096e8c2731@syzkaller.appspotmail.com
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Co-authored-by: Dmitry Kadashev <dkadashev@gmail.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>1 parent 4b93c54 commit 0766ec8
1 file changed
Lines changed: 14 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2514 | 2514 | | |
2515 | 2515 | | |
2516 | 2516 | | |
| 2517 | + | |
2517 | 2518 | | |
2518 | | - | |
2519 | | - | |
| 2519 | + | |
| 2520 | + | |
2520 | 2521 | | |
2521 | 2522 | | |
2522 | 2523 | | |
| |||
2538 | 2539 | | |
2539 | 2540 | | |
2540 | 2541 | | |
2541 | | - | |
2542 | | - | |
2543 | | - | |
2544 | | - | |
2545 | | - | |
2546 | | - | |
2547 | | - | |
2548 | | - | |
2549 | | - | |
2550 | | - | |
2551 | 2542 | | |
2552 | | - | |
| 2543 | + | |
2553 | 2544 | | |
2554 | 2545 | | |
2555 | 2546 | | |
2556 | 2547 | | |
2557 | 2548 | | |
2558 | | - | |
2559 | | - | |
| 2549 | + | |
2560 | 2550 | | |
2561 | 2551 | | |
2562 | 2552 | | |
| |||
2572 | 2562 | | |
2573 | 2563 | | |
2574 | 2564 | | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
| 2573 | + | |
2575 | 2574 | | |
2576 | 2575 | | |
2577 | 2576 | | |
| |||
0 commit comments