Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2274007imb; Mon, 4 Mar 2019 00:26:03 -0800 (PST) X-Google-Smtp-Source: APXvYqwSO6G8WWYLk9pbbjotyAhx5B2wbtoxDQBdSzwIIJQV71tp4bWIeNMr5dbOxuYqnP7l+B6l X-Received: by 2002:a17:902:2dc3:: with SMTP id p61mr18917657plb.166.1551687962989; Mon, 04 Mar 2019 00:26:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551687962; cv=none; d=google.com; s=arc-20160816; b=yTgiTpm7TpvPBG8cjzTGOL1AsDKqTWpnufSHosqpt/mBu3NqdTE5nalq63nW3FO5Wf HVFa/JtYyIbqqCaKFpJoiJ2IRvU+42qlKkS64HSmbMiy31MwDbejIEiX8xAvkP9Zv66V x29V1WCb8jWUC5X87mrxlUGNmRgp6WwJIzeEkFlc5pRFsdJgvUZEvnVDf70mbCz1Pjnz ikJTP8XqB8dEXkzsaViZRaQQ5SvCAWmdPgp3TaGCWkLREKDcueCtlt7PCrETOivdEXsj 5Ng5qRJy60zuKY04hwfSl99bBK3Jz4nAaeI/jOR3H550cRY/kNKeor9C5FAkew1OS4Ih xIBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2X+PTJrc4Iknye4dV9nvs9bLTwVqQfw3jrUi+3Dr7fg=; b=F/O7qfoyRqvRJCTp0MysZOjga2tyX/zeRWq7x0+tVejdorEbX1Vxs8tSnEUJ3GnWEE ElzOGjiRcLtiYyoQVcsGizjOUDyJd+TESxxCUMf+xMAARtxDg/11zYNPYs3DiWPq7KJ4 r96Yfuk13uxSn8FG/f08/NRgNfxwNcdSobC0nqSCSoDYptgv6iUMfk1e7obf/8casnd7 GBF+DU5twHmpBOUyt5mOiw6dOhkMFo2qZKb6uU4OHXNlpdPVlyyhzIDLLikWj8ixUdT6 hUxikpQVVF7QhHDHSfIT9LBxqRySN7GQgrWgfAgigc+9P4bne5lqRlDwyJxMp+LsPAZn d+kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Xgw8zi1d; 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 a8si4644405pff.277.2019.03.04.00.25.47; Mon, 04 Mar 2019 00:26:02 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=Xgw8zi1d; 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 S1726918AbfCDIYn (ORCPT + 99 others); Mon, 4 Mar 2019 03:24:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:42990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726907AbfCDIYm (ORCPT ); Mon, 4 Mar 2019 03:24:42 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D663C214AE; Mon, 4 Mar 2019 08:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551687881; bh=WWMW12dc14MFYFk7qx+CzIjn9iK0Y+kIvrWpC7EWa78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xgw8zi1dmI7Wjdi0kPiw+jAENF2I6gYkjT6HowNaknTHl2TyJeZI9YOiRygbA7jSl C13W5+zV+nbwYb1aRZRujx3kr3SM05EtIZIk2hrnBoXb35gmb/l1YdZ0LdULEgS0cP 1LHANKVbsBeEw4j5mpC/ywDymUb1iJ8CQAU5OHN4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Silvio Cesare , Timur Tabi , Nicolin Chen , Mark Brown , Xiubo Li , Fabio Estevam , Dan Carpenter , Kees Cook , Will Deacon , Greg KH , Willy Tarreau , Sasha Levin Subject: [PATCH 4.14 18/52] ASoC: imx-audmux: change snprintf to scnprintf for possible overflow Date: Mon, 4 Mar 2019 09:22:16 +0100 Message-Id: <20190304081618.336045846@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190304081617.159014799@linuxfoundation.org> References: <20190304081617.159014799@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit c407cd008fd039320d147088b52d0fa34ed3ddcb ] Change snprintf to scnprintf. There are generally two cases where using snprintf causes problems. 1) Uses of size += snprintf(buf, SIZE - size, fmt, ...) In this case, if snprintf would have written more characters than what the buffer size (SIZE) is, then size will end up larger than SIZE. In later uses of snprintf, SIZE - size will result in a negative number, leading to problems. Note that size might already be too large by using size = snprintf before the code reaches a case of size += snprintf. 2) If size is ultimately used as a length parameter for a copy back to user space, then it will potentially allow for a buffer overflow and information disclosure when size is greater than SIZE. When the size is used to index the buffer directly, we can have memory corruption. This also means when size = snprintf... is used, it may also cause problems since size may become large. Copying to userspace is mitigated by the HARDENED_USERCOPY kernel configuration. The solution to these issues is to use scnprintf which returns the number of characters actually written to the buffer, so the size variable will never exceed SIZE. Signed-off-by: Silvio Cesare Cc: Timur Tabi Cc: Nicolin Chen Cc: Mark Brown Cc: Xiubo Li Cc: Fabio Estevam Cc: Dan Carpenter Cc: Kees Cook Cc: Will Deacon Cc: Greg KH Signed-off-by: Willy Tarreau Acked-by: Nicolin Chen Reviewed-by: Kees Cook Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/fsl/imx-audmux.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sound/soc/fsl/imx-audmux.c b/sound/soc/fsl/imx-audmux.c index 392d5eef356d3..99e07b01a2ce9 100644 --- a/sound/soc/fsl/imx-audmux.c +++ b/sound/soc/fsl/imx-audmux.c @@ -86,49 +86,49 @@ static ssize_t audmux_read_file(struct file *file, char __user *user_buf, if (!buf) return -ENOMEM; - ret = snprintf(buf, PAGE_SIZE, "PDCR: %08x\nPTCR: %08x\n", + ret = scnprintf(buf, PAGE_SIZE, "PDCR: %08x\nPTCR: %08x\n", pdcr, ptcr); if (ptcr & IMX_AUDMUX_V2_PTCR_TFSDIR) - ret += snprintf(buf + ret, PAGE_SIZE - ret, + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "TxFS output from %s, ", audmux_port_string((ptcr >> 27) & 0x7)); else - ret += snprintf(buf + ret, PAGE_SIZE - ret, + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "TxFS input, "); if (ptcr & IMX_AUDMUX_V2_PTCR_TCLKDIR) - ret += snprintf(buf + ret, PAGE_SIZE - ret, + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "TxClk output from %s", audmux_port_string((ptcr >> 22) & 0x7)); else - ret += snprintf(buf + ret, PAGE_SIZE - ret, + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "TxClk input"); - ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\n"); if (ptcr & IMX_AUDMUX_V2_PTCR_SYN) { - ret += snprintf(buf + ret, PAGE_SIZE - ret, + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "Port is symmetric"); } else { if (ptcr & IMX_AUDMUX_V2_PTCR_RFSDIR) - ret += snprintf(buf + ret, PAGE_SIZE - ret, + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "RxFS output from %s, ", audmux_port_string((ptcr >> 17) & 0x7)); else - ret += snprintf(buf + ret, PAGE_SIZE - ret, + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "RxFS input, "); if (ptcr & IMX_AUDMUX_V2_PTCR_RCLKDIR) - ret += snprintf(buf + ret, PAGE_SIZE - ret, + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "RxClk output from %s", audmux_port_string((ptcr >> 12) & 0x7)); else - ret += snprintf(buf + ret, PAGE_SIZE - ret, + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "RxClk input"); } - ret += snprintf(buf + ret, PAGE_SIZE - ret, + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\nData received from %s\n", audmux_port_string((pdcr >> 13) & 0x7)); -- 2.19.1