From patchwork Tue Nov 29 11:51:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101444 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1559278qgi; Tue, 29 Nov 2016 03:52:43 -0800 (PST) X-Received: by 10.99.170.5 with SMTP id e5mr49746482pgf.46.1480420363773; Tue, 29 Nov 2016 03:52:43 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a96si30987041pli.220.2016.11.29.03.52.43; Tue, 29 Nov 2016 03:52:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-serial-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-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755201AbcK2Lw1 (ORCPT + 2 others); Tue, 29 Nov 2016 06:52:27 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:64687 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932789AbcK2LwV (ORCPT ); Tue, 29 Nov 2016 06:52:21 -0500 Received: from wuerfel.lan ([78.43.21.235]) by mrelayeu.kundenserver.de (mreue103 [212.227.15.145]) with ESMTPA (Nemesis) id 0Lg6Fn-1cVsC30kvr-00pbqM; Tue, 29 Nov 2016 12:51:12 +0100 From: Arnd Bergmann To: Jiri Slaby , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Peter Hurley , linux-serial@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2, variant A] tty: nozomi: avoid sprintf buffer overflow Date: Tue, 29 Nov 2016 12:51:03 +0100 Message-Id: <20161129115104.1755786-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:AR4r6UtQUzunxLe2/9aVLKFtfn3/QJWhX0rUV5ho0rEiGm600/h uX2FYjV2RwKfMpVwR1h5RgIv55uefH8K7IJoFvU3L2pPiCiv8XCIVRqt+ntWPeVqKhgSogJ 9LCrFe4baqsDx4N2OOeiF6NMUwGws1fzdsrKpAGQHhDRfofLi1yNcHTJistrcNkw0Ca7pG4 zTF1hembrWNHuU8DVjZcg== X-UI-Out-Filterresults: notjunk:1; V01:K0:tIFWgZZNWmQ=:3OmIkkwXMi5OqAnB522IHE d7Dx0+a8pXMAxgqrxbLFseW6Hu9/hTtgnmKHdkV6tdsZlUdG2y7i6fOhdWIPLZbJ8mKi97k+k Qfmehk0vWt1FVed2xJGGIrc6vfV0FVBZ6bKXlO6mefbTr5c/ULZTrtppblvWSHCJqF+t6hXG4 t/+A07zVn7ZUg30HJXK6DuMx8feLPJptDclCVuRPOpXUixgh2Ahkp4JDvDASRKai7kAzMS1QQ XfWKNobfoKKJ1aN+6FMHrgXmgIwXO2gqF+eLkt1jA0NxnuJVKlx26yxusWzjFOq+GNNE1oh/C Lhzzp/ihZtHDp09D2tiFvuVe7ajzMGugMTMo7NAkPHD61ec6mC/gCCabQDDY826NIiBGIMyHb rp/syX7GQ1We8cvwZUVA+OCessEbRgamQisEJxCSshn9al7xgzqNYRMFanqWOB+z5ar40GvNa 8GnpGrvpR2dixRLz9oi9uWz3Ty6gZhVnBtOdl+Nsxive19hPE7OxoA9rap7SCaoaOFQK165UF b2sZ0XpetwtUlbMki6fk7oLqHQvihLCQOAz3/vpz8j0HV9EEDDOnGOnLgQpqhuygjrJIVmJGG +Y+Bg0qyM4BbLt6I+SyAXaolSVnGR0N9GDVEXUGc6ppnGk+q/qbfPhimpibdu4+/xVuB4f8+A pLDJ5mTjleaeL8Cq5lYaG0QH06boawZlLEIrND0AmpXBEy+wneM2TZEgm+KmfW8gKvzw= Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Testing with a gcc-7 snapshot produced an internal compiler error for this file: drivers/tty/nozomi.c: In function 'receive_flow_control': drivers/tty/nozomi.c:919:12: internal compiler error: in get_substring_ranges_for_loc, at input.c:1388 static int receive_flow_control(struct nozomi *dc) I've reported this at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78569 but also noticed that the code line contains a stack overflow, as it prints a string into a slightly shorter fixed-length 'tmp' variable. I don't see any point in the temporary variable, we can simply use pr_debug() to print the output directly. This change should not change any of the output but avoids both the stack overflow and the gcc crash. The stack overflow will not happen unless a module load parameter is also set to enable the debug messages. Signed-off-by: Arnd Bergmann --- I'm posting two versions of the same fix, please choose one or the other as you see fit. --- drivers/tty/nozomi.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) -- 2.9.0 -- To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c index e2020a691058..b17dbfd4f313 100644 --- a/drivers/tty/nozomi.c +++ b/drivers/tty/nozomi.c @@ -68,14 +68,8 @@ /* Default debug printout level */ #define NOZOMI_DEBUG_LEVEL 0x00 -#define P_BUF_SIZE 128 -#define NFO(_err_flag_, args...) \ -do { \ - char tmp[P_BUF_SIZE]; \ - snprintf(tmp, sizeof(tmp), ##args); \ - printk(_err_flag_ "[%d] %s(): %s\n", __LINE__, \ - __func__, tmp); \ -} while (0) +#define NFO(fmt, args...) \ + pr_debug("[%d] %s(): " fmt "\n", __LINE__, __func__, ##args); #define DBG1(args...) D_(0x01, ##args) #define DBG2(args...) D_(0x02, ##args) @@ -91,7 +85,7 @@ do { \ static int debug = NOZOMI_DEBUG_LEVEL; #define D(lvl, args...) do \ - {if (lvl & debug) NFO(KERN_DEBUG, ##args); } \ + {if (lvl & debug) NFO(args); } \ while (0) #define D_(lvl, args...) D(lvl, ##args)