Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2273930imb; Mon, 4 Mar 2019 00:25:53 -0800 (PST) X-Google-Smtp-Source: APXvYqzugKL1Vn2YtWDtERpvCR3uUm1zLmARdPxleMkizH4e3fNHprjhC/dfSeq+BrOgWLZCga1Q X-Received: by 2002:a17:902:8217:: with SMTP id x23mr19575692pln.332.1551687953497; Mon, 04 Mar 2019 00:25:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551687953; cv=none; d=google.com; s=arc-20160816; b=zapfkELyQ8yc/02qsd2YI7Z7pusjzvWOG/LWA1UbmMAoFETghD6pQSmrkSyPL/orNn 1bHv073VOz8j4T7eCDZGUguWAyI3JRkkyV9ZEofgxmKDBVBIZneUT8j5/OXnk+wGOTz1 llpx797hitUviSrM9iZUxegYzt4iLo3Hq3AYLLLG+J0pE61WQJ6Zz3GPRnKR68peYrlt C+/nExeTrvslP08vLBn0w5dP4RjgqWSCau2uYVvbVEkHPRkp31hOzjALwoUYA/MGsHMD tXZ2/5IVxSGudU6dAdLdH7bFp9/heSI16ZclGDyDg5Dd9M/2Ag3gDMHsIdHhCeH0nRct I/rA== 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=pwF/Iihjydz9fwhEku4vvyjIezd9ufzYyWTVVvn0fk4=; b=wfl4Vm0YX3y56c9/oIqcpT0SayFcBABJOKZ9Eb/xmAucbOX+ORV/iZPmZjJUlwtb91 hrf7cK57Nfq/hgoSirUGaN/utBgSkYKDSgeMtzn4VUOB1O3aIh+joFHG5K+iX+SrhvrN HMbiFpBVwFrbxzN2gR0qzBlBvgIRkX1t/XcjGKAambRF8S5vZLVlgIzx8ualAnfQp1mb wRhCiW3dHc7ws5pcZI3dReSaTx/pNZ4Dm+p8rLtUbGEVQmHQgR+32o58VzoaCiZtigeO Ci/bkjtGOrOpDaA0CCBuFSERDlHMAZcbM39NTuai82n/4UqDJi8RYIpeHNRs4/1XYX9M PGzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Tva4zyhS; 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 x2si4848648plo.360.2019.03.04.00.25.38; Mon, 04 Mar 2019 00:25:53 -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=Tva4zyhS; 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 S1726905AbfCDIYk (ORCPT + 99 others); Mon, 4 Mar 2019 03:24:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:42848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbfCDIYj (ORCPT ); Mon, 4 Mar 2019 03:24:39 -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 10E08208E4; Mon, 4 Mar 2019 08:24:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551687878; bh=eY53yrUv32gfdBLVfAzLYrrXxye3pRPhY4WGlXEcxAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tva4zyhSc1D+u8HCjMRVDlRHdclMC9N3ctw+h784fiOXthaJwE4qfXrPh1qPN712f TkTgD1qp0dHt6WuFssSeVPmOiG2QJ/SMgmODwBxJE1EwIT7eVCVIPMNAk6hdysjkPh dZxUuZv1byxhwxbIQpn5khKsgVAxdvocGgKMAEEA= 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.14 17/52] ASoC: dapm: change snprintf to scnprintf for possible overflow Date: Mon, 4 Mar 2019 09:22:15 +0100 Message-Id: <20190304081618.230812099@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 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 53c9d75256393..bba6a917cd02d 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -2009,19 +2009,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"); @@ -2034,7 +2034,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