Blob Blame History Raw
From patchwork Sun Apr 25 23:08:03 2021
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Yuichiro Goto <goto@k-tech.co.jp>
X-Patchwork-Id: 1470141
Return-Path: <u-boot-bounces@lists.denx.de>
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Authentication-Results: ozlabs.org;
 spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de
 (client-ip=85.214.62.61; helo=phobos.denx.de;
 envelope-from=u-boot-bounces@lists.denx.de; receiver=<UNKNOWN>)
Authentication-Results: ozlabs.org;
	dkim=pass (2048-bit key;
 unprotected) header.d=k-tech-co-jp.20150623.gappssmtp.com
 header.i=@k-tech-co-jp.20150623.gappssmtp.com header.a=rsa-sha256
 header.s=20150623 header.b=aG2evrkI;
	dkim-atps=neutral
Received: from phobos.denx.de (phobos.denx.de [85.214.62.61])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by ozlabs.org (Postfix) with ESMTPS id 4FT3cr5pLLz9sV5
	for <incoming@patchwork.ozlabs.org>; Mon, 26 Apr 2021 09:09:16 +1000 (AEST)
Received: from h2850616.stratoserver.net (localhost [IPv6:::1])
	by phobos.denx.de (Postfix) with ESMTP id DAAE481FCD;
	Mon, 26 Apr 2021 01:09:09 +0200 (CEST)
Authentication-Results: phobos.denx.de;
 dmarc=none (p=none dis=none) header.from=k-tech.co.jp
Authentication-Results: phobos.denx.de;
 spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de
Authentication-Results: phobos.denx.de;
	dkim=pass (2048-bit key;
 unprotected) header.d=k-tech-co-jp.20150623.gappssmtp.com
 header.i=@k-tech-co-jp.20150623.gappssmtp.com header.b="aG2evrkI";
	dkim-atps=neutral
Received: by phobos.denx.de (Postfix, from userid 109)
 id 1971382057; Mon, 26 Apr 2021 01:09:06 +0200 (CEST)
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,
 DKIM_VALID,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2
Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com
 [IPv6:2607:f8b0:4864:20::42a])
 (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits))
 (No client certificate requested)
 by phobos.denx.de (Postfix) with ESMTPS id E883680EC1
 for <u-boot@lists.denx.de>; Mon, 26 Apr 2021 01:09:00 +0200 (CEST)
Authentication-Results: phobos.denx.de;
 dmarc=none (p=none dis=none) header.from=k-tech.co.jp
Authentication-Results: phobos.denx.de;
 spf=none smtp.mailfrom=goto@k-tech.co.jp
Received: by mail-pf1-x42a.google.com with SMTP id h11so6707950pfn.0
 for <u-boot@lists.denx.de>; Sun, 25 Apr 2021 16:09:00 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=k-tech-co-jp.20150623.gappssmtp.com; s=20150623;
 h=from:to:cc:subject:date:message-id;
 bh=ToYmsqKBzr3zTVvJdRjIX1oCqkuII+g2LxuLKTcyCm4=;
 b=aG2evrkIlEWR+2+O4uf7Z5Z5dADCoHUqUfa4wv2uGZq16LXSZXAfr96QVEaI+Ysrq9
 S1Wd+94g29kp+qnFc4wLcMUomaZnm0eH+oliBgyqOH/LAB8n7c8avUhcTMJA60McRjeb
 lMsHOX4LwDCbN9Nem+kDEPLIGsYIlg4bQczceWdlw5oHTMNRrj3uqSx1S52Y2xVo9Tl2
 fGiB75T4OGHlO+4ZfXl6Ky1Q6j8eRAp0ysfO9ZY/SjDd8dFowmDn8nCU3Bmy4boJaiK9
 uBxgI8S7h0uSltG+o8KcszPN/fpi2H8oBFuia8kJ1X/mrQ9AK4+n9jA4m5XlsXuyJYon
 NSNA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id;
 bh=ToYmsqKBzr3zTVvJdRjIX1oCqkuII+g2LxuLKTcyCm4=;
 b=idcco1cmfR9jg46QoNPi2i5Xp7KywMSugg82Gr+a6q2d+z8Y0bAWm69vVvCv27OuBe
 EqSikfaPx616hVlE2JSRYhiQjTAkRivx+HbZTOo88Ud3nFuZSye7IzWVgTJQfYeMwk2t
 ur3IC3wNHP8ZJZd7/ncR5bQtEH1dnQnntzZ/ObcQ2qYD7tE8i3XirP+t6bEXgfve6l3z
 h8uhRhUdonx3My77SfoguPZ7agogNuJwKDxEOv2AiQC+sgi6hMSoCM5I/CTY5XBXWBcG
 DsVq6CFis7XI0q4vT+fJnobTZcY+apdx6CQgbTHscvNNANNVQTcW4AmZtdMU00Py7rwl
 +dlw==
X-Gm-Message-State: AOAM530gSI6IYWTUQZeEHkOvsFu+rBGyB3fBUHY4LPk43shM1KC4uXnK
 KlhhaOqM5unov+ya4+knemWrDiRXPLvgHgVJ
X-Google-Smtp-Source: 
 ABdhPJz3Z6j4z6TV4bjvrr75pCyOMhSLC37qICUXTZOgOyojVAW7AH0TT24BTcUVdx8V5n2RwnQzBA==
X-Received: by 2002:a62:8c8c:0:b029:253:31e:55cb with SMTP id
 m134-20020a628c8c0000b0290253031e55cbmr14541132pfd.27.1619392138942;
 Sun, 25 Apr 2021 16:08:58 -0700 (PDT)
Received: from lubuntu1804.flets-east.jp (p1086-maru1shinjuku.tokyo.ocn.ne.jp.
 [61.208.220.86])
 by smtp.gmail.com with ESMTPSA id i63sm9669769pfg.112.2021.04.25.16.08.57
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 25 Apr 2021 16:08:58 -0700 (PDT)
From: Yuichiro Goto <goto@k-tech.co.jp>
To: u-boot@lists.denx.de
Cc: Yuichiro Goto <goto@k-tech.co.jp>, Peter Robinson <pbrobinson@gmail.com>,
 Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Subject: [PATCH v3] IOMUX: Fix buffer overflow in iomux_replace_device()
Date: Mon, 26 Apr 2021 08:08:03 +0900
Message-Id: <20210425230803.3055-1-goto@k-tech.co.jp>
X-Mailer: git-send-email 2.17.1
X-BeenThere: u-boot@lists.denx.de
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: U-Boot discussion <u-boot.lists.denx.de>
List-Unsubscribe: <https://lists.denx.de/options/u-boot>,
 <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>
List-Archive: <https://lists.denx.de/pipermail/u-boot/>
List-Post: <mailto:u-boot@lists.denx.de>
List-Help: <mailto:u-boot-request@lists.denx.de?subject=help>
List-Subscribe: <https://lists.denx.de/listinfo/u-boot>,
 <mailto:u-boot-request@lists.denx.de?subject=subscribe>
Errors-To: u-boot-bounces@lists.denx.de
Sender: "U-Boot" <u-boot-bounces@lists.denx.de>
X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de
X-Virus-Status: Clean

Use of strcat() against an uninitialized buffer would lead
to buffer overflow. This patch fixes it.

Fixes: 694cd5618c ("IOMUX: Introduce iomux_replace_device()")
Signed-off-by: Yuichiro Goto <goto@k-tech.co.jp>
Cc: Peter Robinson <pbrobinson@gmail.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---

Changes for v3:
- Add a Fixes tag in commit message
- Refactor the patch per suggestion from Andy Shevchenko

Changes for v2:
- Add "IOMUX" in title

 common/iomux.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/common/iomux.c b/common/iomux.c
index b9088aa3b5..c428f7110a 100644
--- a/common/iomux.c
+++ b/common/iomux.c
@@ -158,8 +158,12 @@ int iomux_replace_device(const int console, const char *old, const char *new)
 			return -ENOMEM;
 		}
 
-		strcat(tmp, ",");
-		strcat(tmp, name);
+		if (arg) {
+			strcat(tmp, ",");
+			strcat(tmp, name);
+		}
+		else
+			strcpy(tmp, name);
 
 		arg = tmp;
 		size = strlen(tmp) + 1;