Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2887800pxb; Tue, 21 Sep 2021 09:43:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjLiwStF9lJErzGKzWhgKUUfRe3TtyyuM2j1ULs/OYXVCUqCl1ztiq8Ex44IOs6DJIT+OL X-Received: by 2002:a05:6638:4122:: with SMTP id ay34mr847621jab.28.1632242620336; Tue, 21 Sep 2021 09:43:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632242620; cv=none; d=google.com; s=arc-20160816; b=ogmnXEw1nqLwAXllzl8jgY/sqdd4MmxcZC3QScql3tlE6rXDCn17MBeRXCV8OWUEWG m5R9rLzbdiUws/B4HY0TRvFFYbiU3q5fWs9p4DWxtftAfU6RW281x4WnLlbQcjYungi+ mi7IYxzwwdW2ZTQ6VbQoFkiLVKqbVl4yXusT63qg+By+W2MdjQjFRlIGz/zOeL+IYuwI TduXTp/C1e/84N8iAb0gr0RZrTK7TdHpVHc+ZPMV7vbWF3vPrCOb/J/ViZRtzSLLEUZY 7hOX2gYBsqWUFtEF19U6ZLOvgkaRR0CFGewofjF1yGqlee/2E8tAZUKi2D8b5y7U+IJd NhYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=y9/p8UT6XMNyd/8OKyW671IeFdUR2a1ME2bzSTT0Uaw=; b=UhfStA5FBkfWXtMxCrqRxbG+Ez88+3rSnAKiZZFoLzYFXXLPc44vqMl9ser6NC/Y2X XtJJqr2b3sfieRtmDfWFOSHNRHF7q3Pp7Xz4fTFwR99TQlqaeJv4DdYdnKi5yWLwECjv t/rp4ffFQW57ipCDAZpZ6QJj5PoFHh3ojZS1qI359z3YxK+/bTgLuBg8wIyy4KdqH9b1 zduwktoBgRmpIipjrsOvbhOlm5KDzGmVeVmbpz5ALWhO8eSCvL1I87G85cMnitBJ8cWu ZCbNJhZquxck/JjUjgPAmfZYuTahqg2xeUtO2tjY4RQZDKkh2ueNdlO4V8Yh6IWe4DjY 4U2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=IRaI7Sop; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=KNCm8Paf; 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=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i12si16252152jac.26.2021.09.21.09.43.24; Tue, 21 Sep 2021 09:43:40 -0700 (PDT) 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=@suse.de header.s=susede2_rsa header.b=IRaI7Sop; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=KNCm8Paf; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229471AbhIUQmz (ORCPT + 99 others); Tue, 21 Sep 2021 12:42:55 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:59554 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbhIUQmy (ORCPT ); Tue, 21 Sep 2021 12:42:54 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 12CFF2217A; Tue, 21 Sep 2021 16:41:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1632242485; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=y9/p8UT6XMNyd/8OKyW671IeFdUR2a1ME2bzSTT0Uaw=; b=IRaI7Sop8R0IUfhVkJtQBCHmbLiGjy36ZuVEP5ygv1Xm9I9+SpYjd27VylKbwrZRZae0at uz8Que0alKaogm0WE7kgUOzTD4ONQdDaYBbBbBCmzJCnHwqgns3V3eIS+Eq3heOWRupRab Bz3NmaukG9Nh3aYxLKybPxFHZ8mtnsw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1632242485; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=y9/p8UT6XMNyd/8OKyW671IeFdUR2a1ME2bzSTT0Uaw=; b=KNCm8PafKIQyPfmcUJjMb2zIrWnMk2D7TbKpOxfAQK4ZbbBuN2vX9qPmZghVZYvoUWxsQF oNC7WZXgwnfgauAg== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id B2223A3B90; Tue, 21 Sep 2021 16:41:24 +0000 (UTC) Date: Tue, 21 Sep 2021 18:41:24 +0200 Message-ID: From: Takashi Iwai To: Len Baker Cc: Jaroslav Kysela , Takashi Iwai , gushengxian , Kees Cook , "Gustavo A. R. Silva" , alsa-devel@alsa-project.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ALSA: usx2y: Prefer struct_size over open coded arithmetic In-Reply-To: <20210919133727.44694-1-len.baker@gmx.com> References: <20210919133727.44694-1-len.baker@gmx.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 19 Sep 2021 15:37:27 +0200, Len Baker wrote: > > As noted in the "Deprecated Interfaces, Language Features, Attributes, > and Conventions" documentation [1], size calculations (especially > multiplication) should not be performed in memory allocator (or similar) > function arguments due to the risk of them overflowing. This could lead > to values wrapping around and a smaller allocation being made than the > caller was expecting. Using those allocations could lead to linear > overflows of heap memory and other misbehaviors. > > In this case this is not actually dynamic size: all the operands > involved in the calculation are constant values. However it is better to > refactor this anyway, just to keep the open-coded math idiom out of > code. > > So, use the struct_size() helper to do the arithmetic instead of the > argument "size + size * count" in the kzalloc() function. > > Also, take the opportunity to refactor the declaration variables to make > it more easy to read. > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments > > Signed-off-by: Len Baker Thanks, applied. Takashi