gfs2: avoid %pS in pr_err() fallback to prevent vsnprintf crash
PATCH 1/1 gfs2: avoid %pS in pr_err() fallback to prevent vsnprintf crash
While debugging a syzbot report, I found that the %pS format in dump_holder() can trigger a crash when we end up in the pr_err() fallback path. This happens because %pS goes through symbol resolution inside vsnprintf, and in this case that isn’t always safe.
I switched the seq_file case to continue using %pS, since it is useful there, but changed the pr_err() path to use %p instead. This way we still print a valid pointer address without risking a kernel oops from within printk itself. The idea is to keep the debugging value but make it more robust.
--- fs/gfs2/glock.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
fs/gfs2/glock.c +12 -4
@@ -2284,10 +2284,18 @@ static void dump_holder(struct seq_file *seq, const struct gfs2_holder *gh,if (gh_owner) comm = gh_owner->comm; } -gfs2_print_dbg (seq,"%s H: s:%s f:%s e:%d p:%ld [%s] %pS\n" , - fs_id_buf,state2str (gh->gh_state), -hflags2str (flags_buf, gh->gh_flags, gh->gh_iflags), - gh->gh_error, (long )owner_pid, comm, (void *)gh->gh_ip); +if (seq) { +gfs2_print_dbg (seq,"%s H: s:%s f:%s e:%d p:%ld [%s] %pS\n" , + fs_id_buf,state2str (gh->gh_state), +hflags2str (flags_buf, gh->gh_flags, gh->gh_iflags), + gh->gh_error, (long )owner_pid, comm, (void *)gh->gh_ip); + }else { +gfs2_print_dbg (seq,"%s H: s:%s f:%s e:%d p:%ld [%s] %p\n" , + fs_id_buf,state2str (gh->gh_state), +hflags2str (flags_buf, gh->gh_flags, gh->gh_iflags), + gh->gh_error, (long )owner_pid, comm, + (void *)gh->gh_ip); + }rcu_read_unlock (); }
Signature · 1 line
2.34.1
Andreas Gruenbacher
maintainerQuoted 4 lines · Kriish Sharma
While debugging a syzbot report, I found that the %pS format in
dump_holder()can trigger a crash when we end up in thepr_err()fallback path. This happens because %pS goes through symbol resolution inside vsnprintf, and in this case that isn’t always safe.
I'm unconvinced -- when and why is %pS not safe to use?
Thanks,
Andreas