Skip to content

Commit 5405cb3

Browse files
samitolvanengregkh
authored andcommitted
Commit 9bb48c8 ("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. also in n_tty and change the comparisons to use write_iter instead of write.
commit 9f12e37 upstream. [ Also moved the declaration of redirected_tty_write() to the proper location in a header file. The reason for the bug was the bogus extern declaration in n_tty.c silently not matching the changed definition in tty_io.c, and because it wasn't in a shared header file, there was no cross-checking of the declaration. Sami noticed because Clang's Control Flow Integrity checking ended up incidentally noticing the inconsistent declaration. - Linus ] Fixes: 9bb48c8 ("tty: implement write_iter") Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e857271 commit 5405cb3

3 files changed

Lines changed: 3 additions & 7 deletions

File tree

drivers/tty/n_tty.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,9 +2079,6 @@ static int canon_copy_from_read_buf(struct tty_struct *tty,
20792079
return 0;
20802080
}
20812081

2082-
extern ssize_t redirected_tty_write(struct file *, const char __user *,
2083-
size_t, loff_t *);
2084-
20852082
/**
20862083
* job_control - check job control
20872084
* @tty: tty
@@ -2103,7 +2100,7 @@ static int job_control(struct tty_struct *tty, struct file *file)
21032100
/* NOTE: not yet done after every sleep pending a thorough
21042101
check of the logic of this change. -- jlc */
21052102
/* don't stop on /dev/console */
2106-
if (file->f_op->write == redirected_tty_write)
2103+
if (file->f_op->write_iter == redirected_tty_write)
21072104
return 0;
21082105

21092106
return __tty_check_change(tty, SIGTTIN);
@@ -2307,7 +2304,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
23072304
ssize_t retval = 0;
23082305

23092306
/* Job control check -- must be done at start (POSIX.1 7.1.1.4). */
2310-
if (L_TOSTOP(tty) && file->f_op->write != redirected_tty_write) {
2307+
if (L_TOSTOP(tty) && file->f_op->write_iter != redirected_tty_write) {
23112308
retval = tty_check_change(tty);
23122309
if (retval)
23132310
return retval;

drivers/tty/tty_io.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,8 @@ DEFINE_MUTEX(tty_mutex);
144144

145145
static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
146146
static ssize_t tty_write(struct kiocb *, struct iov_iter *);
147-
ssize_t redirected_tty_write(struct kiocb *, struct iov_iter *);
148147
static __poll_t tty_poll(struct file *, poll_table *);
149148
static int tty_open(struct inode *, struct file *);
150-
long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
151149
#ifdef CONFIG_COMPAT
152150
static long tty_compat_ioctl(struct file *file, unsigned int cmd,
153151
unsigned long arg);

include/linux/tty.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ extern void tty_kclose(struct tty_struct *tty);
422422
extern int tty_dev_name_to_number(const char *name, dev_t *number);
423423
extern int tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout);
424424
extern void tty_ldisc_unlock(struct tty_struct *tty);
425+
extern ssize_t redirected_tty_write(struct kiocb *, struct iov_iter *);
425426
#else
426427
static inline void tty_kref_put(struct tty_struct *tty)
427428
{ }

0 commit comments

Comments
 (0)