Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1357088pxb; Fri, 21 Jan 2022 16:24:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7EBWijpTPf3VwM8UR7cpst6UgIb5qc6YLx2mOnV53e5/y+4j6RCwNIqNiWxmWgSY9Atov X-Received: by 2002:a17:90b:28d:: with SMTP id az13mr3010001pjb.7.1642811056762; Fri, 21 Jan 2022 16:24:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642811056; cv=none; d=google.com; s=arc-20160816; b=MES48UofdEtwVnZ4zed8CH8TG8UJEY9pe7cSkD8MtVvH1LULz5DLwfw9b+3B6earrr eNopYJA2shRC6JYedeu8fAdntjArh98COKM++sVngPdEqe6w7afmyrqVoVXiC0ZR5oF8 /PYxvJliWba9wRkmWwo2sf1lE0H0vhgefZasAiQ3tm9RvrdFDnImQBc+5gAlo/l4FUJN sSolN919qBE4DF2IeUy9fdxvo6UQPeENp4sXX9+hYN80XbFxcZ4c/Q3CZoNqvVRq9iV8 d33LhV5EKqkk8PJ1gwc0mRLQtuGa1ajvKQK7g8UHCxXlIbv8NPNeIBg1GMNi5rhUQpZX bCdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=egMwIptYpGbsC4XxY+2pETIXKwRmweD4aAOClQc8FOg=; b=vaAdK6bkThyuchdlOPX2vjmkHCbuQpXDJjBwT1Ln/W9zj285GJ2YRMwl+Nlbf4vEMC cM7aNSxv/mknvu57bmZCRExZ/EzW9yEIzVt8dQGoAI9ducSNQdGvfdRAkXEGvk9YBHYY L0Kw6El3nq4/kNHagdxAFflHOl/2iQk1psiU2yZAoQ1qPSE5o0tJ+uf4WdmmLF54+Fxk F2YG4hU/in2cRhApc2+dQWGwFM5Ire0UjNO5394u2aoYrVfRWrTeBYcF1LvzEBlgxcxD Oim2XFBt8L8S/TID5d4UQEf+KSEow10Gbp/FxUV31XskvYa8d7BqLEfGFW+EHfgDqF+f 3iUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=j4GGCU1L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t6si8558120pfj.19.2022.01.21.16.24.04; Fri, 21 Jan 2022 16:24:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=j4GGCU1L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378268AbiATXW0 (ORCPT + 99 others); Thu, 20 Jan 2022 18:22:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244408AbiATXWN (ORCPT ); Thu, 20 Jan 2022 18:22:13 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47B17C061574 for ; Thu, 20 Jan 2022 15:22:13 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id e28so2772670pfj.5 for ; Thu, 20 Jan 2022 15:22:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=egMwIptYpGbsC4XxY+2pETIXKwRmweD4aAOClQc8FOg=; b=j4GGCU1LW7aQgvrd+Lz43oPyrQTqCIyQoc6damDU85BEiX4EjPHox+J6XMEr6p37Ug FUVyNP5vcpMg6VQVjWSQsAXBlSyyHvX1azVDGc6U6R65pQjxW9MeXOI5KViTR8vEFY8o ANrlB37o2SeyYSXsKBblX32sWYT9tDRU319IY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=egMwIptYpGbsC4XxY+2pETIXKwRmweD4aAOClQc8FOg=; b=0Qvrmx5LaPbIIQme/h/I5FHgrfB3fcg+ddtXTBPfSXfL8CaJgelgmWpWJ27aGfGtT5 KjT7b5vNpUeAb6MT/3hlZ/5pxblkMT88vuSb97zIYCwBIfP61x3/mT7KwTM/odxVB8UK xtbbmAUxmKZskSrNH4sDm90sK+KugC+pu29B9G7ZdtjQh56nkblGe78y7sQITYKwaI5h nszd3huhsnCwewujvwEWFJT4WgPi0rZhb5STQUUD2HANO8UeTlhIy0nI1Ac6N+webhfC ATVV5/DXC5Aln13bttgz+Fa711Q6S1cdjzUqJMhZRe/iP86rPwbdK65Q8aAROIP9LdAn vmGQ== X-Gm-Message-State: AOAM532Azmd4jaOXONvkP8lh+jwXuv6LZ7Zb5rQbXSyI2EdyFE/JzCsv tM4J/20ZwcKPYWDUWYJSvEksxg== X-Received: by 2002:a63:1d7:: with SMTP id 206mr840156pgb.111.1642720932694; Thu, 20 Jan 2022 15:22:12 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x18sm3202700pgj.41.2022.01.20.15.22.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 15:22:12 -0800 (PST) Date: Thu, 20 Jan 2022 15:22:11 -0800 From: Kees Cook To: "Gustavo A. R. Silva" Cc: "Geoffrey D. Bennett" , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2][next] ALSA: usb-audio: scarlett2: Use struct_size() helper in scarlett2_usb() Message-ID: <202201201522.5E744C15E9@keescook> References: <20220120211600.GA28841@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220120211600.GA28841@embeddedor> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 20, 2022 at 03:16:00PM -0600, Gustavo A. R. Silva wrote: > Make use of the struct_size() helper instead of an open-coded version, > in order to avoid any potential type mistakes or integer overflows that, > in the worst scenario, could lead to heap overflows. > > Also, address the following sparse warnings: > sound/usb/mixer_scarlett_gen2.c:1064:28: warning: using sizeof on a flexible structure > sound/usb/mixer_scarlett_gen2.c:1065:29: warning: using sizeof on a flexible structure > > Link: https://github.com/KSPP/linux/issues/174 > Signed-off-by: Gustavo A. R. Silva Looks good to me! Reviewed-by: Kees Cook > --- > Changes in v2: > - Use correct format specifier %zu for type size_t argument. > > sound/usb/mixer_scarlett_gen2.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c > index 53ebabf42472..7ff8a4817c67 100644 > --- a/sound/usb/mixer_scarlett_gen2.c > +++ b/sound/usb/mixer_scarlett_gen2.c > @@ -1061,9 +1061,9 @@ static int scarlett2_usb( > { > struct scarlett2_data *private = mixer->private_data; > struct usb_device *dev = mixer->chip->dev; > - u16 req_buf_size = sizeof(struct scarlett2_usb_packet) + req_size; > - u16 resp_buf_size = sizeof(struct scarlett2_usb_packet) + resp_size; > struct scarlett2_usb_packet *req, *resp = NULL; > + size_t req_buf_size = struct_size(req, data, req_size); > + size_t resp_buf_size = struct_size(resp, data, resp_size); > int err; > > req = kmalloc(req_buf_size, GFP_KERNEL); > @@ -1111,7 +1111,7 @@ static int scarlett2_usb( > usb_audio_err( > mixer->chip, > "Scarlett Gen 2/3 USB response result cmd %x was %d " > - "expected %d\n", > + "expected %zu\n", > cmd, err, resp_buf_size); > err = -EINVAL; > goto unlock; > -- > 2.27.0 > -- Kees Cook