aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg KH <greg@kroah.com>2018-10-04 14:06:14 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-10-11 13:50:00 -0400
commitb97b3d9fb57860a60592859e332de7759fd54c2e (patch)
tree79b21a2681fb9fee48b022d6072aa6500cf3de7d
parentc9a8e5fce009e3c601a43c49ea9dbcb25d1ffac5 (diff)
tty: wipe buffer if not echoing data
If we are not echoing the data to userspace or the console is in icanon mode, then perhaps it is a "secret" so we should wipe it once we are done with it. This mirrors the logic that the audit code has. Reported-by: aszlig <aszlig@nix.build> Tested-by: Milan Broz <gmazyland@gmail.com> Tested-by: Daniel Zatovic <daniel.zatovic@gmail.com> Tested-by: aszlig <aszlig@nix.build> Cc: Willy Tarreau <w@1wt.eu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/tty/n_tty.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 431742201709..3ad460219fd6 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -152,17 +152,28 @@ static inline unsigned char *echo_buf_addr(struct n_tty_data *ldata, size_t i)
152 return &ldata->echo_buf[i & (N_TTY_BUF_SIZE - 1)]; 152 return &ldata->echo_buf[i & (N_TTY_BUF_SIZE - 1)];
153} 153}
154 154
155/* If we are not echoing the data, perhaps this is a secret so erase it */
156static void zero_buffer(struct tty_struct *tty, u8 *buffer, int size)
157{
158 bool icanon = !!L_ICANON(tty);
159 bool no_echo = !L_ECHO(tty);
160
161 if (icanon && no_echo)
162 memset(buffer, 0x00, size);
163}
164
155static int tty_copy_to_user(struct tty_struct *tty, void __user *to, 165static int tty_copy_to_user(struct tty_struct *tty, void __user *to,
156 size_t tail, size_t n) 166 size_t tail, size_t n)
157{ 167{
158 struct n_tty_data *ldata = tty->disc_data; 168 struct n_tty_data *ldata = tty->disc_data;
159 size_t size = N_TTY_BUF_SIZE - tail; 169 size_t size = N_TTY_BUF_SIZE - tail;
160 const void *from = read_buf_addr(ldata, tail); 170 void *from = read_buf_addr(ldata, tail);
161 int uncopied; 171 int uncopied;
162 172
163 if (n > size) { 173 if (n > size) {
164 tty_audit_add_data(tty, from, size); 174 tty_audit_add_data(tty, from, size);
165 uncopied = copy_to_user(to, from, size); 175 uncopied = copy_to_user(to, from, size);
176 zero_buffer(tty, from, size - uncopied);
166 if (uncopied) 177 if (uncopied)
167 return uncopied; 178 return uncopied;
168 to += size; 179 to += size;
@@ -171,7 +182,9 @@ static int tty_copy_to_user(struct tty_struct *tty, void __user *to,
171 } 182 }
172 183
173 tty_audit_add_data(tty, from, n); 184 tty_audit_add_data(tty, from, n);
174 return copy_to_user(to, from, n); 185 uncopied = copy_to_user(to, from, n);
186 zero_buffer(tty, from, n - uncopied);
187 return uncopied;
175} 188}
176 189
177/** 190/**
@@ -1960,11 +1973,12 @@ static int copy_from_read_buf(struct tty_struct *tty,
1960 n = min(head - ldata->read_tail, N_TTY_BUF_SIZE - tail); 1973 n = min(head - ldata->read_tail, N_TTY_BUF_SIZE - tail);
1961 n = min(*nr, n); 1974 n = min(*nr, n);
1962 if (n) { 1975 if (n) {
1963 const unsigned char *from = read_buf_addr(ldata, tail); 1976 unsigned char *from = read_buf_addr(ldata, tail);
1964 retval = copy_to_user(*b, from, n); 1977 retval = copy_to_user(*b, from, n);
1965 n -= retval; 1978 n -= retval;
1966 is_eof = n == 1 && *from == EOF_CHAR(tty); 1979 is_eof = n == 1 && *from == EOF_CHAR(tty);
1967 tty_audit_add_data(tty, from, n); 1980 tty_audit_add_data(tty, from, n);
1981 zero_buffer(tty, from, n);
1968 smp_store_release(&ldata->read_tail, ldata->read_tail + n); 1982 smp_store_release(&ldata->read_tail, ldata->read_tail + n);
1969 /* Turn single EOF into zero-length read */ 1983 /* Turn single EOF into zero-length read */
1970 if (L_EXTPROC(tty) && ldata->icanon && is_eof && 1984 if (L_EXTPROC(tty) && ldata->icanon && is_eof &&