Skip to content

Commit 9f12e37

Browse files
samitolvanentorvalds
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 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 <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 007ad27 commit 9f12e37

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

drivers/tty/n_tty.c

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

2084-
extern ssize_t redirected_tty_write(struct file *, const char __user *,
2085-
size_t, loff_t *);
2086-
20872084
/**
20882085
* job_control - check job control
20892086
* @tty: tty
@@ -2105,7 +2102,7 @@ static int job_control(struct tty_struct *tty, struct file *file)
21052102
/* NOTE: not yet done after every sleep pending a thorough
21062103
check of the logic of this change. -- jlc */
21072104
/* don't stop on /dev/console */
2108-
if (file->f_op->write == redirected_tty_write)
2105+
if (file->f_op->write_iter == redirected_tty_write)
21092106
return 0;
21102107

21112108
return __tty_check_change(tty, SIGTTIN);
@@ -2309,7 +2306,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
23092306
ssize_t retval = 0;
23102307

23112308
/* Job control check -- must be done at start (POSIX.1 7.1.1.4). */
2312-
if (L_TOSTOP(tty) && file->f_op->write != redirected_tty_write) {
2309+
if (L_TOSTOP(tty) && file->f_op->write_iter != redirected_tty_write) {
23132310
retval = tty_check_change(tty);
23142311
if (retval)
23152312
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
@@ -421,6 +421,7 @@ extern void tty_kclose(struct tty_struct *tty);
421421
extern int tty_dev_name_to_number(const char *name, dev_t *number);
422422
extern int tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout);
423423
extern void tty_ldisc_unlock(struct tty_struct *tty);
424+
extern ssize_t redirected_tty_write(struct kiocb *, struct iov_iter *);
424425
#else
425426
static inline void tty_kref_put(struct tty_struct *tty)
426427
{ }

0 commit comments

Comments
 (0)