n_tty: fix redirected_tty_write checks after write_iter conversion
PATCH 1/1 n_tty: fix redirected_tty_write checks after write_iter conversion
Commit 9bb48c82aced ("tty: implement write_iter") converted the tty layer to use write_iter. Fix the redirected_tty_write declaration also in n_tty and change the comparisons to use write_iter instead of write.
--- drivers/tty/n_tty.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/tty/n_tty.c +3 -4
@@ -2081,8 +2081,7 @@ static int canon_copy_from_read_buf(struct tty_struct *tty,return 0 ; } -extern ssize_t redirected_tty_write (struct file *,const char __user *, -size_t ,loff_t *); +extern ssize_t redirected_tty_write (struct kiocb *,struct iov_iter *);/** * job_control - check job control
@@ -2105,7 +2104,7 @@ static int job_control(struct tty_struct *tty, struct file *file)/* NOTE: not yet done after every sleep pending a thorough check of the logic of this change. -- jlc */ /* don't stop on /dev/console */ -if (file->f_op->write == redirected_tty_write) +if (file->f_op->write_iter == redirected_tty_write)return 0 ;return __tty_check_change (tty,SIGTTIN );
@@ -2309,7 +2308,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,ssize_t retval =0 ;/* Job control check -- must be done at start (POSIX.1 7.1.1.4). */ -if (L_TOSTOP (tty) && file->f_op->write != redirected_tty_write) { +if (L_TOSTOP (tty) && file->f_op->write_iter != redirected_tty_write) { retval =tty_check_change (tty);if (retval)return retval;
base-commit: 6ee1d745b7c9fd573fba142a2efdad76a9f1cb04
Signature · 1 line
2.30.0.280.ga3ce27912f-goog
Quoted 5 lines · Sami Tolvanen
Commit
9bb48c82aced("tty: implementwrite_iter") converted the tty layer to usewrite_iter. Fix theredirected_tty_writedeclaration also inn_ttyand change the comparisons to usewrite_iterinstead of write.
Duh.
Obvious ACK from me.
The only thing I'd ask is that the declaration for redirected_tty_write() be moved to a proper header file (<linux/tty.h>.
Because the reason I didn't notice this was literally that n_tty.c did its own private 'extern' declaration of that function. Which is horribly wrong, exactly because it doesn't then ever notice when the declaration is changed.
So I'd suggest doing the patch as attached - but please keep Sami's credit, this is purely a "declare the function in the proper place" fix.
Linus
Quoted 2 lines · Linus Torvalds
Obvious ACK from me.
Greg - if you have nothing else lined up in the tty tree, I can take this fix directly if it's easier.
And Sami - how did you actually notice? Some lint-like tool, or is there something that actually broke from n_tty not handling a redirected tty right?
Linus
Greg Kroah-Hartman
maintainerQuoted 7 lines · Linus Torvalds
Quoted 2 lines · Linus Torvalds
Obvious ACK from me.
Greg - if you have nothing else lined up in the tty tree, I can take this fix directly if it's easier.
I have nothing else that I know of, so yes, it is easier for you to take it directly, thanks!
greg k-h
Quoted 3 lines · Greg Kroah-Hartman
I have nothing else that I know of, so yes, it is easier for you to take it directly, thanks!
It's top-of-tree right now, commit 9f12e37cae44.
And I just noticed I screwed up the formatting when editing the patch
- after pushing out. I deleted the actual top line.
Darn.
Linus
Quoted 4 lines · Linus Torvalds
Quoted 1 line · Linus Torvalds
Quoted 8 lines
Quoted 1 line
Obvious ACK from me.
Greg - if you have nothing else lined up in the tty tree, I can take this fix directly if it's easier.
And Sami - how did you actually notice? Some lint-like tool, or is there something that actually broke from
n_ttynot handling a redirected tty right?
Neither, I noticed this because the conflicting function declarations broke Clang's Control Flow Integrity checking.
Sami
Quoted 3 lines · Sami Tolvanen
Neither, I noticed this because the conflicting function declarations broke Clang's Control Flow Integrity checking.
Ahh, interesting. Is that automated somewhere, or are you running your own special checks? It sounds like a useful thing.
I was thinking that maybe I should make some sparse-based cross-file checker, but it sounds like -fsanitize=cfi (or whatever it is you do) catches it.
Linus
Quoted 8 lines · Linus Torvalds
Quoted 3 lines · Sami Tolvanen
Neither, I noticed this because the conflicting function declarations broke Clang's Control Flow Integrity checking.
Ahh, interesting. Is that automated somewhere, or are you running your own special checks? It sounds like a useful thing.
I’m running a continuous integration script locally, which tests a few basic kernel configurations with CFI to ensure they compile and boot. We’re using CFI in Android kernels, so this helps catch issues before they reach stable kernels.
Quoted 3 lines
I was thinking that maybe I should make some sparse-based cross-file checker, but it sounds like -fsanitize=cfi (or whatever it is you do) catches it.
That might still be useful, because CFI only adds runtime checking. It’s primarily a mitigation against code reuse attacks, but it does find these types of issues occasionally.
Sami