Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2519575imu; Thu, 29 Nov 2018 06:19:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/XiJ67cTpBBQ4NS80HDKjXHRAOELvIOdWjsMN93w5mY5vm7727SelR5JWucsX3/W00EDUyQ X-Received: by 2002:a17:902:9045:: with SMTP id w5mr1602656plz.32.1543501191210; Thu, 29 Nov 2018 06:19:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501191; cv=none; d=google.com; s=arc-20160816; b=i4s7hab3HMLIN83rHGaWRpaX8y/mBQbkD6b14HoYSYnmrVEzJYIQfD46OuHWeqX+0M 7D+cJszzrbeGAk/BE4ETBoikzj1rj9gXpg/Ot7+s5V0eYL8lV7njDZNB6mM8GvJwtqR1 LcrSmnR7JONVYWumX2EV9TQyx0bxPzPT7IOcWNHbds4UJhsL8nnbvUhV3QH5xinq04p9 prkYfYo8+v2znfCGyrHn40a/ciM5v9hqhE1gWt9tCjj30mTI+2rtheAw5pLQuE4sG9jC TBOh/L/YT3FdFoQbX+ftgsEmBKsmUt45WaGM5iC1+prsK50Go2PZNDRVOva+FTVgVA3l lQjg== 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=I4Zt3zFqSH0pUlitTGl3IAuQ9Pyg//u22l6kgVMZ6+E=; b=fbLsLYblN6L18oK8qNx/5bCVQW1aTrb/nZPizdpmTykA8T+VT9eVWfrMzqWLcp0l2C LmLUlNLuUTpMB3ZyDzxoCeGcYe7ng2U+KVMAvKbl5Z/ncj+hSjqWI6zkTHXgzxCm6mkO kofbaJVzA3p70/PPmb/QvXidvU3KijAUeHldOoC0ItOeV/lvvOJHWrG4AG0nChQuF36Z MVX9MRZYuVR0XMrsPpZrMsaNexpU39Vbeg/bPR8jC3qWzNI/26zCLTQedofX8MenYq32 iN/Iu/WTazlsVuMNk1za8g9JR2HeHvaoPEuS5IaUHT/wDzeKOo9g1LbaPlXflgWEpp0A ta2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eu+eXaMr; 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.19.36; Thu, 29 Nov 2018 06:19:51 -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=eu+eXaMr; 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 S1730028AbeK3BV7 (ORCPT + 99 others); Thu, 29 Nov 2018 20:21:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:43502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728865AbeK3BV6 (ORCPT ); Thu, 29 Nov 2018 20:21:58 -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 18B79208E7; Thu, 29 Nov 2018 14:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543500988; bh=Cq6t3JH39L+YvapXndr8WEDyMxL0v+4VjfAtTd4B/Sk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eu+eXaMrN4682vLnYqzUmCQfAib09kKfkG/eq+FwslguKXnEC4jVy8tPzEkUwXz4d qOhKaBGfGjDcXp3WG38QQbLofCFsn/zqQtZDnAR2ALu1+42Fm4Lx02xmyQSwOvgbD3 C9b3V/PEFcTXUDxEVR0tF5DeI4UJzihCRNJkpjcY= 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 3.18 81/83] tty: wipe buffer if not echoing data Date: Thu, 29 Nov 2018 15:12:39 +0100 Message-Id: <20181129140142.655336408@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140138.002176596@linuxfoundation.org> References: <20181129140138.002176596@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 3.18-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 | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -188,15 +188,29 @@ static int receive_room(struct tty_struc return left; } +/* If we are not echoing the data, perhaps this is a secret so erase it */ +static inline 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 inline int tty_copy_to_user(struct tty_struct *tty, void __user *to, - const void *from, + void *from, unsigned long n) { struct n_tty_data *ldata = tty->disc_data; + int retval; tty_audit_add_data(tty, from, n, ldata->icanon); - return copy_to_user(to, from, n); + retval = copy_to_user(to, from, n); + if (!retval) + zero_buffer(tty, from, n); + return retval; } /** @@ -2006,6 +2020,7 @@ static int copy_from_read_buf(struct tty is_eof = n == 1 && read_buf(ldata, tail) == EOF_CHAR(tty); tty_audit_add_data(tty, read_buf_addr(ldata, tail), n, ldata->icanon); + zero_buffer(tty, read_buf_addr(ldata, tail), n); ldata->read_tail += n; /* Turn single EOF into zero-length read */ if (L_EXTPROC(tty) && ldata->icanon && is_eof && !read_cnt(ldata))