Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp2419077ima; Mon, 22 Oct 2018 09:24:37 -0700 (PDT) X-Google-Smtp-Source: ACcGV61LjE0ZJRoQHNg+dqt/bXXtjQcLz3IJXqvGYJhyZXcZ+iid5pKp7C4GIm4T2olcvxVb/JJY X-Received: by 2002:a63:30c8:: with SMTP id w191-v6mr42791518pgw.447.1540225477658; Mon, 22 Oct 2018 09:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540225477; cv=none; d=google.com; s=arc-20160816; b=RhYkwFBixEatiobdsqsb1dPGF8Z6+NF00Ht8uvg2pXXczTdnVg6eBc1M637pCh/3Os v+rwC+9v3vtAqELfCYAlmbqDFldNSlt0AatUW/SIqWT2g80uw5cZne7JbmDNtagiEoev ZVu5FV9wCH8KWMjVzs1usccyd7BfZimEKQ2KENQ+Fvpe6NDO6gMGxuSkIPI6H0Ln80mV 7lPxoSB1chtWOaYVZxQOgolaEvwksyuCNn94SIt4KRFbqbE7sYZcxnizKm3F20k+omdi H/jk20q/Goj8DpHjlH2Tvji7GBH0GHURAbhbaGexLeDeeuInnPpy9I2HT41hyK11aJvy X6/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=z8gyyeDbO4HJhydjcJgM99H+IHgFXim+aoB5geR1Amw=; b=CHnkZ+frJzhB0K+j+Kbtj8Cq8ivF31RRJzGhlgEcgEGBkcBqcA8LLtSb+BbP8SZNH3 fMEwCJ1s0a3kQpFLA5lt9zNlzlFY1ks8eUc026xLmeEzYSa40ePb5rPTy+vhHYYXfg8O zUxbuBT2ustXA/JO69unNhuhlCCMrdmdAtWp87qpUdBN0fk3LWTh9wgbdjTf0Ai7f+1m 9blfwkMdE3TgsotiOalwV8To7cVId/c7TeTCYgVpwufnuTe2zfWeaBJqbGyUp0WyBrTp C+EzGv2Q/io3Exnyi1495CPqeLXmd2utGTHKkaXwv92TPicVmSLt+tFs/Lkckr1+Ig7K y1dg== 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 h3-v6si34486415plh.124.2018.10.22.09.24.22; Mon, 22 Oct 2018 09:24:37 -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 S1728589AbeJWAiV (ORCPT + 99 others); Mon, 22 Oct 2018 20:38:21 -0400 Received: from mga12.intel.com ([192.55.52.136]:3026 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727554AbeJWAiU (ORCPT ); Mon, 22 Oct 2018 20:38:20 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Oct 2018 09:19:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,412,1534834800"; d="scan'208";a="84637544" Received: from hanvin-mobl2.amr.corp.intel.com ([10.255.77.70]) by orsmga006.jf.intel.com with ESMTP; 22 Oct 2018 09:19:09 -0700 From: "H. Peter Anvin (Intel)" To: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Cc: "H. Peter Anvin" , 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, Alan Cox , stable@vger.kernel.org Subject: [PATCH stable v2 1/2] termios, tty/tty_baudrate.c: fix buffer overrun Date: Mon, 22 Oct 2018 09:19:04 -0700 Message-Id: <20181022161905.26589-1-hpa@zytor.com> X-Mailer: git-send-email 2.14.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "H. Peter Anvin" 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.14.4