Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3850366imm; Mon, 8 Oct 2018 10:30:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV63L2dNvb2qG8nMhnWcM0j7EgVy+tp6wIzjhiPdnP9slUnpc3Y/8quzgeNhLcEm/XS+NgbES X-Received: by 2002:a63:df06:: with SMTP id u6-v6mr22009193pgg.202.1539019849491; Mon, 08 Oct 2018 10:30:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539019849; cv=none; d=google.com; s=arc-20160816; b=a+kT1ec3XElrT1zF/IV0Rw+VvYJHlCAm1lWqy12BGPcVow9nKr7JnmT3TPG5x//8FB 8tLJgFNb5PrGlBuRsye8EGC8s2VTbHz3MsPXo7o2m6zq2HusHQ29bEGTjJG+ktBAa7q5 gxsjUwGojBhbEHQYOAuW6B9M55BNS9+sMq2+/oEqXOtIHaFfikUUbg9yBm0eYO7p6Ts9 iLbXTdjT6M8+38vIaEwFC8QGLzZV+rWwNAwM/4jd9ibodbt6yA0Xwm3f6EyU/8ITt0qs TjUL3gXvyfnRAjyknXHa2mIOXRjYL2JfhEstr9bbgMkHkv1+w4XXQ7oclrUowXrxxlCz C+AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject; bh=KU0jA8ys3/9EFczLkjRN0hl3yTOonkXaW6vf0CcjbqE=; b=pUzFJnzzWQ426VqKi38iv4W90L4e+rU/jxwygUQckSg2HxitHJ6nyE0sYobJmGENGP sIoAMzckXFIyM1PQPONW25UF5/YplyMMw2VByjMPWEMrKj/vg7X6gumMDgSW3YJ+sm5C 9DL7mgMo5xel0uRhAjw7DhCzVpnQlrEvjf4hEL+XSfRjUXJsQ3y24xEza7XhEo/TVJNQ fruiqRyYhcxWCc8sMs3yW5LWPbsneqKk4vUPT09yvmezAP3p+NEMCs+a23sV55L4s9zZ o9sZULlJPZ5dUgsYzGw/uDLI/D6bZupcYuAi0P1u1eUgohIwmInGMpDrC9W9SWwlZ6yW tOLQ== ARC-Authentication-Results: i=1; mx.google.com; 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 f62-v6si9809662plf.288.2018.10.08.10.30.33; Mon, 08 Oct 2018 10:30:49 -0700 (PDT) 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; 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 S1726647AbeJIAnM (ORCPT + 99 others); Mon, 8 Oct 2018 20:43:12 -0400 Received: from terminus.zytor.com ([198.137.202.136]:52325 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726291AbeJIAnL (ORCPT ); Mon, 8 Oct 2018 20:43:11 -0400 Received: from carbon-x1.hos.anvin.org (c-24-5-245-234.hsd1.ca.comcast.net [24.5.245.234] (may be forged)) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id w98HTv3P698334 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 8 Oct 2018 10:29:58 -0700 Subject: Re: [PATCH stable v2 2/2] termios, tty/tty_baudrate.c: simplify, auto-generate baud table To: Johan Hovold Cc: linux-kernel@vger.kernel.org, Tobias Klausmann , Greg Kroah-Hartman , Jiri Slaby , Al Viro , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Gleixner , Kate Stewart , Philippe Ombredanne , Eugene Syromiatnikov , linux-alpha@vger.kernel.org, linux-serial@vger.kernel.org, Alan Cox , stable@vger.kernel.org References: <20181008040620.1248277-1-hpa@zytor.com> <20181008040620.1248277-3-hpa@zytor.com> <20181008154655.GE3332@localhost> From: "H. Peter Anvin" Message-ID: Date: Mon, 8 Oct 2018 10:29:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <20181008154655.GE3332@localhost> Content-Type: multipart/mixed; boundary="------------16E7F5314AD1487554F5F572" Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a multi-part message in MIME format. --------------16E7F5314AD1487554F5F572 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 10/8/18 8:46 AM, Johan Hovold wrote: > > So we need a minimal fix for this only as this patch in particular > should not be backported to stable. > > I'm not sure when I'll have time to review this one thoroughly, so > perhaps others can chime in meanwhile. > > Johan > OK. In the past Greg has generally liked to avoid fixes which will diverge from upstream (because code in stable which is not in upstream can make debugging difficult), but this is the minimal patch as requested; which to apply is up to Greg. As far as reviewing the cleanup patch, I strongly recommend: a) Looking at the resulting file, not at the patch. Most of the code is simply merging the input and output rate functions into a common help function, and restructuring the code to that the utterly bizarre coding of a for loop using a do { ... } while() loop with the initial condition set at variable declaration(!!) far from the loop itself. b) Examine bmacros.h after a build. c) Build drivers/tty/tty_baudrate.s. You can directly examine the baud_table and verify that it is, indeed, correct for whatever architecture you build. -hpa --------------16E7F5314AD1487554F5F572 Content-Type: text/x-patch; name="0002-termios-tty-tty_baudrate.c-fix-buffer-overrun.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0002-termios-tty-tty_baudrate.c-fix-buffer-overrun.patch" From c8195635f63508f4c75ef553b4703c4cc3c750e2 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 8 Oct 2018 09:32:00 -0700 Subject: [PATCH 02/16] termios, tty/tty_baudrate.c: fix buffer overrun On architectures with CBAUDEX == 0 (Alpha and PowerPC), the code in tty_baudrate.c does not do any limit checking on the tty_baudrate[] array, and in fact a buffer overrun is possible on both architectures. Add a limit check to prevent that situation. This will be followed by a much bigger cleanup/simplification patch. Signed-off-by: H. Peter Anvin (Intel) Requested-by: Cc: Johan Hovold Cc: Greg Kroah-Hartman Cc: Jiri Slaby Cc: Al Viro Cc: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner Cc: Thomas Gleixner Cc: Kate Stewart Cc: Philippe Ombredanne Cc: Greg Kroah-Hartman Cc: Eugene Syromiatnikov Cc: Cc: Cc: Alan Cox Cc: --- drivers/tty/tty_baudrate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/tty_baudrate.c b/drivers/tty/tty_baudrate.c index 7576ceace571..f438eaa68246 100644 --- a/drivers/tty/tty_baudrate.c +++ b/drivers/tty/tty_baudrate.c @@ -77,7 +77,7 @@ speed_t tty_termios_baud_rate(struct ktermios *termios) else cbaud += 15; } - return baud_table[cbaud]; + return cbaud >= n_baud_table ? 0 : baud_table[cbaud]; } EXPORT_SYMBOL(tty_termios_baud_rate); @@ -113,7 +113,7 @@ speed_t tty_termios_input_baud_rate(struct ktermios *termios) else cbaud += 15; } - return baud_table[cbaud]; + return cbaud >= n_baud_table ? 0 : baud_table[cbaud]; #else /* IBSHIFT */ return tty_termios_baud_rate(termios); #endif /* IBSHIFT */ -- 2.17.1 --------------16E7F5314AD1487554F5F572--