Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2272892imb; Mon, 4 Mar 2019 00:23:41 -0800 (PST) X-Google-Smtp-Source: APXvYqytrq7OaAcGVivK61ypS2gwMeLTmxXII2MqJ8DjJzqwPAJOOZsc61H+MiDhUMhwRNxDM2lC X-Received: by 2002:a63:6ecb:: with SMTP id j194mr17937163pgc.250.1551687821700; Mon, 04 Mar 2019 00:23:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551687821; cv=none; d=google.com; s=arc-20160816; b=QwNRdPIuAowPs3d1Kpx625W6+USveia+g53TmnA3E8dh30o2vsPHKKfsahDIqqg9UR 8aiejWv5T9M8cKDH5aN1evDNY8EcMq7kSCHsqjh+keyREJ6lkPFoe+m5yUxTcrCaBALz e6KuFO5ErU00VLXXKGXXRReFWqSVedcHpTElCyDFbe6tXaE3MzKUSICTBXH74reHo/eH +vwKFXhcydDNwr3irJ4oXdOfOmbMjtc4ifFBoNHpWox3hZyRRUvd3EnMdAmHAqfqQ5aj lyMRyzBBLw7T+fOuNmwK4PwDTnm7Z8PoMFpDQoK4m+ohTvJSMAT+fD6ZplO+FYSFk42W OfLw== 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=7Fx2oN1iLPU271yjnnaaHrwYtSc+4c/H6IVZOUx92AY=; b=oUA7nK812NSazmRXb0oCwiVcyXd376y7xptXpLsXMaWwE2YF/tylsEKwmlBpiZqj8g GKrMAKh/ml6D8jz3tKaKSCHjnAjPkyeKYZ5afxpe8H8VhzeCBSexo7pNJqgcUFLFhwTO TwksgN82l8H0x/GkWVnmpQOCZolmJxe1JzDtX9SWEGeBAHPHLYIRxw4YpjYuPHZh4zol CelUr/EhW9VwtvQmWoYxld2W0ZeGO7IQfb7onyMPldn+oKOOL63yx6acCT8oNdGNLFuD MPg4VxF8u1DvvSD53BNiaLV9IiPc9OaYomjZHBneuMV+EKK8NsPRSaMlVnw+uMZJGihf zyzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H4lavx7U; 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 k17si4762511pgg.437.2019.03.04.00.23.24; Mon, 04 Mar 2019 00:23:41 -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=H4lavx7U; 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 S1726269AbfCDIWo (ORCPT + 99 others); Mon, 4 Mar 2019 03:22:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:37422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726237AbfCDIWl (ORCPT ); Mon, 4 Mar 2019 03:22:41 -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 C996B208E4; Mon, 4 Mar 2019 08:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551687760; bh=KUXqz8QVOw/6U2MEgJRCzN5XW5AVA2fhkm0Ey9eOCw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H4lavx7U6pbt90Tdp5dQVwfb84bg8kfx6V5EXwoHW8R4eMmFPMWrFNTqE2RSCIEdL ugvv3/bWuSXLEKUuFNXgm3hq9Aes/hRMQxg2mBgZoV1OLA1LY4t3hYqPG0qsR2k+kX P/VXfdFnQ0xYp/EGlzK+oC5XMZ9tsqHspFqtkHTM= 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.9 12/32] ASoC: dapm: change snprintf to scnprintf for possible overflow Date: Mon, 4 Mar 2019 09:22:00 +0100 Message-Id: <20190304081603.183583900@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190304081602.307094059@linuxfoundation.org> References: <20190304081602.307094059@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.9-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 8bfc534e3b342..ab647f1fe11bd 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -1976,19 +1976,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"); @@ -2001,7 +2001,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