Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1975552pxb; Fri, 5 Mar 2021 04:34:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUDHPXXCnCukRP4PHd8tThbdAGdT5cWfy/2CaUyRDnXV+40u6JeaX6YZFfdP39DoPbuukJ X-Received: by 2002:a17:906:7754:: with SMTP id o20mr2072346ejn.209.1614947649745; Fri, 05 Mar 2021 04:34:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614947649; cv=none; d=google.com; s=arc-20160816; b=nkLvQmVhxEtiZGspyv5EcllFU6nJO7YAl2nGbHwSak/K/0/hsHsPDTagIhe9UJVrok n4RIzJxn36VqvdHoiL/Xxe9XSNdGGkooYi4Sxfnd//E8GYJJaHsNRd8pYbOQZOAhfPwS FVGQyPGR0mUH2B3j1HkSXXM9p7jKEYC6jFP7/f7KGPUjRrMa5QGNsLrL/rmWVhtgmpBb qhGeGVMA0DbqfCOO1heqCb+sw9LJhOLJ55q4b5IHSSgdM71F2qsCaX+HMd7If/K6yVu5 4owFyjNIm20updzUDulIoA0VjUKV7bxErLtdI9lHdNhOVw95QjrJHTy9YMqOscoxg3a8 3Uhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4R0oaBhL02PDw6sBeAF2Y626QyFUzTRAdra0XU963Go=; b=NUqktNGsjUMIq6RasESg7Q/AP6vhAez4N5lYZo/up1AAFzW5OCfPTdaFAYybENAvf4 jq6FkJjd/1BKI3b7Pgx+uDPk7VVaSaVCngr4C6g5puVg/YnIIojmaCWpVL6WdVJns6t+ NRU3fXA1CIejJcrZxzoYNzOmNngPPuElMYmOW7Zb5ePdiIAfs91xAMyuu8zW2A1uG+O8 WBMTqMPkmH9BPb7Tb2Woq1Me+Rx1hv4NqJFNP/jW7GibCfxXUaeHl68QIQsXD+Kjurzs 2QUTmzkPQmZHEvd3uKCScIfHu1ZxOJaM7lz+qWVVVTiXvxlHr7jgwmHoJhTU+B1belb2 tjtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PYXRXuIe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e6si1460464edv.313.2021.03.05.04.33.46; Fri, 05 Mar 2021 04:34:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PYXRXuIe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232113AbhCEMct (ORCPT + 99 others); Fri, 5 Mar 2021 07:32:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:42312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232536AbhCEMcD (ORCPT ); Fri, 5 Mar 2021 07:32:03 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0690465004; Fri, 5 Mar 2021 12:32:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614947523; bh=+S58+QLx3ePuw2zu29LSutDOGxJGNBNL+1TN4eKkVJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PYXRXuIeVsz+V9HMDGwzXLDtrQsqk8wBM+LUFSXMNFytoj1gg0U5rzXsryomRLfaH ByQK/0mBHmJrtMWwpiCyGgg6+A5sK9R+n4eNXrRX136P9zPYBJs1aU6yZUoMrU6STG kFe7ddILvNKSft/rPQBobaEP508d4EXv7kmnTMhw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby , Linus Torvalds Subject: [PATCH 5.10 094/102] tty: fix up iterate_tty_read() EOVERFLOW handling Date: Fri, 5 Mar 2021 13:21:53 +0100 Message-Id: <20210305120907.904466423@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305120903.276489876@linuxfoundation.org> References: <20210305120903.276489876@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linus Torvalds commit e71a8d5cf4b4f274740e31b601216071e2a11afa upstream. When I converted the tty_ldisc_ops 'read()' function to take a kernel pointer, I was a bit too aggressive about the ldisc returning EOVERFLOW. Yes, we want to have EOVERFLOW override any partially read data (because the whole point is that the buffer was too small for the whole packet, and we don't want to see partial packets), but it shouldn't override a previous EFAULT. And in fact, it really is just EOVERFLOW that is special and should throw away any partially read data, not "any error". Admittedly EOVERFLOW is currently the only one that can happen for a continuation read - and if the first read iteration returns an error we won't have this issue. So this is more of a technicality, but let's just make the intent very explicit, and re-organize the error handling a bit so that this is all clearer. Reported-by: Jiri Slaby Signed-off-by: Linus Torvalds Reviewed-by: Jiri Slaby Link: https://lore.kernel.org/r/CAHk-=wh+-rGsa=xruEWdg_fJViFG8rN9bpLrfLz=_yBYh2tBhA@mail.gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/tty_io.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -860,13 +860,20 @@ static int iterate_tty_read(struct tty_l if (!size) break; - /* - * A ldisc read error return will override any previously copied - * data (eg -EOVERFLOW from HDLC) - */ if (size < 0) { - memzero_explicit(kernel_buf, sizeof(kernel_buf)); - return size; + /* Did we have an earlier error (ie -EFAULT)? */ + if (retval) + break; + retval = size; + + /* + * -EOVERFLOW means we didn't have enough space + * for a whole packet, and we shouldn't return + * a partial result. + */ + if (retval == -EOVERFLOW) + offset = 0; + break; } copied = copy_to_iter(kernel_buf, size, to);