Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2531425imu; Thu, 29 Nov 2018 06:29:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/UUat1Idnf8lnb3NDFs/c/EfQ9MauyMg0FLCkZIt7/SCgCrwxvO5lMCZMYjFfHqntCS0QxX X-Received: by 2002:a17:902:b78b:: with SMTP id e11mr1708522pls.90.1543501772965; Thu, 29 Nov 2018 06:29:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501772; cv=none; d=google.com; s=arc-20160816; b=NT9DifdFOzJN51XQzboHtJVrCBhYulTsK0525ZrPUHnp6JBklmX+Dysewc00K1psHL gX2D+jGqGsoWKVdUTKKaUdohuxwEcV6yw0aKgCpBFHFhHAs4PQlKRP8Whw9BMcn4NBWU NYtK91rGI8hzSZROvSwyAjM2B/cb3lAiIhe+nN7dXYgejG4cih143Gg54S2ykVb1eQPI mf0b9WNpkgXQ6u1BI+40eodBwxJCBL5TCKMZCQMM3efULakJsi4xkimE/tW4CyrU78b0 N93KDEi/bJggytHEuK7Mnp2yRDW//0QVZzq2bDjoVXgWz8qHRmxEVO3kpx9/qeyw+05t BYbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XpViRVBTFpih1gDgISO+8IxfCzac4Q/3hFe0RP1D/mQ=; b=sS6fUFfVTMP7HWT4hYTOF90BK4vheBnH4jhfwwlSESCnPyYgV6gzXFe2Z9/KOQpTwD gpECHuaJYbcEsYtQl8nzFKsD7oOtO/AryX6wDrC3jdk1Yj6lvsDXkdmOS8U9Jeo1WOsY lgPnYz0/VMVIzakjebxJwGktHQ8PscuI+Ugl5T3pk7hORziUEHsrFAiI/0P6e4QcyX/x Lodslb6z9mXZLSZgekWI7jnh+Ov6OEyC9+RksP3fZKlIDgHRAZrlu4TDRRpIkGrCgTG8 zGsb0WasB4yBpjT149q29OhDd7KfpVGD75nr/vmm9knFuiece0JXNCoCTcvy18RsOsU2 Vb/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U5SQ73SU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f95si2508308plb.60.2018.11.29.06.29.18; Thu, 29 Nov 2018 06:29:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U5SQ73SU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388036AbeK3Bdx (ORCPT + 99 others); Thu, 29 Nov 2018 20:33:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:34750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733011AbeK3Bdw (ORCPT ); Thu, 29 Nov 2018 20:33:52 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BD129213A2; Thu, 29 Nov 2018 14:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501700; bh=jXu99XRM2fys48vFQm8x+MG749JNQ5fEs0B9Y6XNrlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U5SQ73SU7H8Jf34uTCZ5vCsD4LelZKAjCqyjLTRQqRwRDmR0rp46P1wUYPtBbiFvJ ROPflTkpAz6DW28pFJf6xHQwUSbFJLnkLBHuVSVg/DC+DGWkicTwseYCzf4bmq+5+u LCO0JKpDDAPlS1LPO2fh/ILO/jF2ow1/bD3UfknE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, aszlig , Milan Broz , Daniel Zatovic , Willy Tarreau Subject: [PATCH 4.14 090/100] tty: wipe buffer if not echoing data Date: Thu, 29 Nov 2018 15:13:00 +0100 Message-Id: <20181129140106.581594215@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140058.768942700@linuxfoundation.org> References: <20181129140058.768942700@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Greg Kroah-Hartman commit b97b3d9fb57860a60592859e332de7759fd54c2e upstream. 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 Tested-by: Milan Broz Tested-by: Daniel Zatovic Tested-by: aszlig Cc: Willy Tarreau Signed-off-by: Greg Kroah-Hartman --- drivers/tty/n_tty.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -154,17 +154,28 @@ static inline unsigned char *echo_buf_ad return &ldata->echo_buf[i & (N_TTY_BUF_SIZE - 1)]; } +/* If we are not echoing the data, perhaps this is a secret so erase it */ +static void zero_buffer(struct tty_struct *tty, u8 *buffer, int size) +{ + bool icanon = !!L_ICANON(tty); + bool no_echo = !L_ECHO(tty); + + if (icanon && no_echo) + memset(buffer, 0x00, size); +} + static int tty_copy_to_user(struct tty_struct *tty, void __user *to, size_t tail, size_t n) { struct n_tty_data *ldata = tty->disc_data; size_t size = N_TTY_BUF_SIZE - tail; - const void *from = read_buf_addr(ldata, tail); + void *from = read_buf_addr(ldata, tail); int uncopied; if (n > size) { tty_audit_add_data(tty, from, size); uncopied = copy_to_user(to, from, size); + zero_buffer(tty, from, size - uncopied); if (uncopied) return uncopied; to += size; @@ -173,7 +184,9 @@ static int tty_copy_to_user(struct tty_s } tty_audit_add_data(tty, from, n); - return copy_to_user(to, from, n); + uncopied = copy_to_user(to, from, n); + zero_buffer(tty, from, n - uncopied); + return uncopied; } /** @@ -1962,11 +1975,12 @@ static int copy_from_read_buf(struct tty n = min(head - ldata->read_tail, N_TTY_BUF_SIZE - tail); n = min(*nr, n); if (n) { - const unsigned char *from = read_buf_addr(ldata, tail); + unsigned char *from = read_buf_addr(ldata, tail); retval = copy_to_user(*b, from, n); n -= retval; is_eof = n == 1 && *from == EOF_CHAR(tty); tty_audit_add_data(tty, from, n); + zero_buffer(tty, from, n); smp_store_release(&ldata->read_tail, ldata->read_tail + n); /* Turn single EOF into zero-length read */ if (L_EXTPROC(tty) && ldata->icanon && is_eof &&