Stephen Brennan 0766ec82e5 namei: Fix use after free in kern_path_locked
In 0ee50b47532a ("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: 0ee50b47532a ("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>
2021-09-07 15:56:16 -04:00
..
2021-09-02 09:21:27 -07:00
2021-08-19 09:02:55 +09:00
2021-09-02 09:21:27 -07:00
2021-09-02 09:21:27 -07:00
2021-04-12 15:04:29 +02:00
2021-09-02 09:21:27 -07:00
2021-07-06 11:06:04 -07:00
2021-09-02 09:21:27 -07:00
2021-09-04 10:48:47 -07:00
2021-09-02 12:32:12 -07:00
2021-09-02 09:21:27 -07:00
2021-09-02 09:21:27 -07:00
2021-09-04 10:25:26 -07:00
2021-09-04 10:25:26 -07:00
2021-07-06 20:14:41 -04:00
2021-09-02 15:09:46 -07:00
\n
2021-08-30 10:04:31 -07:00
2021-08-18 22:08:24 +02:00
2021-09-03 18:42:01 +02:00
2021-06-30 12:21:16 -07:00
2021-06-29 10:53:48 -07:00
2021-09-03 15:33:47 -07:00
2021-08-16 10:50:32 -06:00
2021-08-19 09:02:55 +09:00
2021-09-02 09:21:27 -07:00
\n
2021-08-30 10:24:50 -07:00
2021-08-30 19:30:30 -07:00
2021-08-31 11:13:35 -07:00
2021-08-31 12:00:07 -07:00
2021-08-31 11:13:35 -07:00
2021-09-06 09:26:07 -07:00
2021-08-31 11:06:32 -07:00
2021-06-29 10:53:48 -07:00
2021-08-18 22:08:24 +02:00
2021-02-21 11:02:48 -08:00
2021-08-10 17:57:22 +02:00