From patchwork Mon Jan 18 03:49:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Boichat X-Patchwork-Id: 8052141 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B6C669F440 for ; Mon, 18 Jan 2016 03:50:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E20332010F for ; Mon, 18 Jan 2016 03:50:04 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 7DAF0200F2 for ; Mon, 18 Jan 2016 03:50:03 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 08251261A76; Mon, 18 Jan 2016 04:50:02 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id F323C2604D5; Mon, 18 Jan 2016 04:49:53 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 60B532604F8; Mon, 18 Jan 2016 04:49:52 +0100 (CET) Received: from mail-pf0-f172.google.com (mail-pf0-f172.google.com [209.85.192.172]) by alsa0.perex.cz (Postfix) with ESMTP id E9587260481 for ; Mon, 18 Jan 2016 04:49:46 +0100 (CET) Received: by mail-pf0-f172.google.com with SMTP id e65so150698571pfe.0 for ; Sun, 17 Jan 2016 19:49:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=FNyAmVHOkrFymp8MrzMYRcE/hKcPJ5kHFUJikUT/Ego=; b=ANa32X7zWt1WIZRZ9utEOZYUEzyXdb2V3QbXJ4kpI3bOj0X+4/b/VPRTR9VS/tYdkK EnA8hQ7wLYmkWWcBwP1vCu4ePvHw8b5oGZ6oxCoJAOQZ2bNujrgRpEPZ8YNJXvWfZyPN HUf3c4HlQAOkz0vyV0raHNzUtJrY6x2OJwqoo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FNyAmVHOkrFymp8MrzMYRcE/hKcPJ5kHFUJikUT/Ego=; b=BvQtyAJt3/v3n/y2PbWA3Nwl7XGYruUaif4CFwG61DOK1j+23rMMW/Y+FZ6UgaXCEW 3gA4cbOaz4C/HakDQAY1tFUmUi6j2LmXYdXt+rZjCVvJVo4zIevX7UWA5bx/EBnqLMcZ FiewNQvw+VIlHFUHr3D04nMFbE7Hyey7azjlFtVmJK+WLvBMuox9sJw30oEi9IKF8CkC dB2916WkH+Ju/bBjH2MYMhc1av04vZE/GE3d2Pwmss4+DBHBgnP/plYuyeg7NNOXuy/x rHW2MnJe+TpBfjZPG91/upHuVkw8rQ2gFLLQfuBHf5w0BhJU6jeHtYaelKkT+HZ0Lw/9 TqNg== X-Gm-Message-State: ALoCoQkz70whDo+MFvN1rWrs/Hi4V/Fyxbm6btN+snSlhsEh2Wor8KzZLx3K7i1IQ++uo7Qv9PiqQxUp5ezYRCBv+z7wTlGhKw== X-Received: by 10.98.18.2 with SMTP id a2mr33504580pfj.145.1453088984955; Sun, 17 Jan 2016 19:49:44 -0800 (PST) Received: from drinkcat.tpe.corp.google.com ([172.30.210.53]) by smtp.gmail.com with ESMTPSA id dz12sm30087624pac.2.2016.01.17.19.49.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 17 Jan 2016 19:49:44 -0800 (PST) From: Nicolas Boichat To: Takashi Iwai Date: Mon, 18 Jan 2016 11:49:18 +0800 Message-Id: <1453088958-6214-1-git-send-email-drinkcat@chromium.org> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Nicolas Boichat , Pierre-Louis Bossart Subject: [alsa-devel] [PATCH] ALSA: pcm: Fix snd_pcm_hw_params struct copy in compat mode X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Running a kernel with KASan enabled, we spotted that the following read in sound/soc/soc-pcm.c:soc_pcm_hw_params() is out of bounds: /* copy params for each codec */ codec_params = *params; The problem comes from sound/core/pcm_compat.c, snd_pcm_ioctl_hw_params_compat, where we're copying from a struct snd_pcm_hw_params to a struct snd_pcm_hw_params32: /* only fifo_size is different, so just copy all */ data = memdup_user(data32, sizeof(*data32)); It turns out that snd_pcm_hw_params is 4 bytes longer than snd_pcm_hw_params32, that's why an out-of-bounds read happens. We separate kmalloc and memory copy operations to make sure data has the correct length. Signed-off-by: Nicolas Boichat --- sound/core/pcm_compat.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c index b48b434..9630e9f 100644 --- a/sound/core/pcm_compat.c +++ b/sound/core/pcm_compat.c @@ -255,10 +255,15 @@ static int snd_pcm_ioctl_hw_params_compat(struct snd_pcm_substream *substream, if (! (runtime = substream->runtime)) return -ENOTTY; - /* only fifo_size is different, so just copy all */ - data = memdup_user(data32, sizeof(*data32)); - if (IS_ERR(data)) - return PTR_ERR(data); + data = kmalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + /* only fifo_size (RO from userspace) is different, so just copy all */ + if (copy_from_user(data, data32, sizeof(*data32))) { + err = -EFAULT; + goto error; + } if (refine) err = snd_pcm_hw_refine(substream, data);