Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2278575imb; Mon, 4 Mar 2019 00:34:52 -0800 (PST) X-Google-Smtp-Source: APXvYqwnX/zZu1UE/1gcVnuhVbmIdC81AnFJXe51R7wPu8J5b5dmgjL8dMD9zC3AHgj0xLK61bY6 X-Received: by 2002:a63:3548:: with SMTP id c69mr17809244pga.256.1551688492787; Mon, 04 Mar 2019 00:34:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551688492; cv=none; d=google.com; s=arc-20160816; b=l/0yGaFTqyUbt5/SGus18pAZDbslSGQ154+H16QadFlWyp7e/OmvgHSZN/+dWsn3H/ Ku5NWHEhHRt8lXw3qZTmmPl23qqHqqGsVRYaETWu+49YSLQvPQyGbIRPlg77w3NoDILl 8u8guAMo9Y7cOr+9BLRkSPWpssNxnLeUMge/uvnWOoyEuf65XFZk4FM7qJTyCHZB31/V M8fHUaHfZfSLlQhz3vJAhKxA/m8L/yLjuId/KB1owaaxwj5l3RgBcrZjkMbhlcEV0S2e o0mWocLuPkBE0GWTgAxpCqs+qEAWkJx4JViRkDKaeUSgQW86ApxmmGQD3DjMkC+sde+B ZPQw== 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=LDfYGuaUfQbllD+1T+Tpb8JOHL9mDT9yx2J7NLVI9x0=; b=LJWQhxcD6u2OsLbbXlpw2Sidy1wYQM52huZ3loKmHnfiQQbN7h4hQTHy/bd+N9JrUV VnDuFmebU6AsfvazAJuLZ/wkSkMlJNmnLyqJg4EN9afMWnk5tSlN1LDIHXY7u8sbtcWx 6sNiPfeQTi0wmDOGJKxKszY0rviJHCviB5PaYESX4QcJ/IzfuZmT+4uWgfu9IA0n4KTy CemdIp2CnYHv57CZhZe3o0Ro8shbq8yR+E5/RDeqq8WvYF1yEUF9k+cMQPd7cnCrW1Cv LYD6fdASdXaGGyZJ7jbjy1s+hZljrlf17aNBI+a17RHB0eYkbK+K+ZMngM/RGzJp78XS XXeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="rdXpJ6/h"; 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 q20si4745075pls.263.2019.03.04.00.34.35; Mon, 04 Mar 2019 00:34:52 -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="rdXpJ6/h"; 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 S1728118AbfCDIcq (ORCPT + 99 others); Mon, 4 Mar 2019 03:32:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:36512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727071AbfCDIco (ORCPT ); Mon, 4 Mar 2019 03:32:44 -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 D79CE20823; Mon, 4 Mar 2019 08:32:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551688363; bh=3//xFH1BEFkYS/SUlJUpyHUC3jABfIw/baqKv+DGq4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rdXpJ6/hEwzV4HjTK+YJrOapInflyWqY+PhDRnboUgH2JdbZt+oZHmWvSfzNrzDgR XHekdmFswWmPH/YijrhSM+h9sttmgeW6spZ2NgoFfzUGZ2Ffr4ASx3T1sRfBggQ5ea +ARCkANdewVsgVH3adFzXXaeiUrvQ1OwUdpKiMIg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Silvio Cesare , Liam Girdwood , Mark Brown , Dan Carpenter , Kees Cook , Will Deacon , Greg KH , Willy Tarreau , Sasha Levin Subject: [PATCH 4.20 22/88] ASoC: dapm: change snprintf to scnprintf for possible overflow Date: Mon, 4 Mar 2019 09:22:05 +0100 Message-Id: <20190304081631.486520032@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190304081630.610632175@linuxfoundation.org> References: <20190304081630.610632175@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.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit e581e151e965bf1f2815dd94620b638fec4d0a7e ] 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: Liam Girdwood Cc: Mark Brown Cc: Dan Carpenter Cc: Kees Cook Cc: Will Deacon Cc: Greg KH Signed-off-by: Willy Tarreau Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/soc-dapm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index a5178845065b3..2c4c134195392 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -2019,19 +2019,19 @@ static ssize_t dapm_widget_power_read_file(struct file *file, out = is_connected_output_ep(w, NULL, NULL); } - ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d", + ret = scnprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d", w->name, w->power ? "On" : "Off", w->force ? " (forced)" : "", in, out); if (w->reg >= 0) - ret += snprintf(buf + ret, PAGE_SIZE - ret, + ret += scnprintf(buf + ret, PAGE_SIZE - ret, " - R%d(0x%x) mask 0x%x", w->reg, w->reg, w->mask << w->shift); - ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\n"); if (w->sname) - ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", + ret += scnprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", w->sname, w->active ? "active" : "inactive"); @@ -2044,7 +2044,7 @@ static ssize_t dapm_widget_power_read_file(struct file *file, if (!p->connect) continue; - ret += snprintf(buf + ret, PAGE_SIZE - ret, + ret += scnprintf(buf + ret, PAGE_SIZE - ret, " %s \"%s\" \"%s\"\n", (rdir == SND_SOC_DAPM_DIR_IN) ? "in" : "out", p->name ? p->name : "static", -- 2.19.1