Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp992580imu; Fri, 11 Jan 2019 12:53:29 -0800 (PST) X-Google-Smtp-Source: ALg8bN6WQANVGFfuP4dKRYtVuEbvV5AXRDyTs/3bYUJ/pSp2AgMfkL4BnXHI3s8dUmYv0bmSD/+0 X-Received: by 2002:a63:b543:: with SMTP id u3mr14608877pgo.420.1547240009608; Fri, 11 Jan 2019 12:53:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547240009; cv=none; d=google.com; s=arc-20160816; b=WCKs8Xq0uKkRg6lz4ReIA2hRtvw147YAPQjxp/WW55RV41E37y+MWHFq/ZNNCAc/fc obGLZKmD1daG0YJ8vXFUMXxGi3SUfQJfbLoeZLz26q9E9+Shvb8hVTt3OwYM4GLU3UQ9 3nK1I+AKMubUohYMPzPD3CHqQzkgfpGe9FaY7MmVPCMPqLfpeZ6nxLQUCjjCRCy/wlvm B1FthOl0gY/tUykCPQNVVYwGn0u0/45oQlWBNe9QSnXQfkCL3OKwVrvymqWaHlb2xAum Ow5x2fUA0NtE24prIEqnU1eihhfVSEeuetqpipGWnNXeWBGFXthJRRf4h76Ry0/ZXlgK yAYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=yTgfkkdtMIoi23ux2f75q9TFNcJ9LY9AiM9jb/rIyCA=; b=XH4P8tKXgk1GIfdgMiCHP507Jhaq0ElaFeW92SRrjtW/nvsdk2CXRPys4V7Rz7944l WHli/8jcpecZBwLe4VnCfNb5Sjd+kt69H2/0ygnFNA0U6Dib4cIfpGKL3TJ/2rqbny9X Q0XB8uZXXA1ikKK5xu0Qwwc6r9n2xE+bk1NdOE6Y/OAEB8gNkc6ewkAE9ZTILF/jnrOM 71EAKPGGGIwNJuzZ4t+5jr4pw0k88/G5s8ECtgVP7+Z8tY552joXDFgUZ4fEqBX1bG74 IAwURZqDLDeGzXsZa7UGl6aRdhtn8drNATkHHRS3QUlGHER9Y/e3vYLTfESabSn5neYn gxTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=HqWRPPSN; 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 193si8861992pgc.220.2019.01.11.12.53.13; Fri, 11 Jan 2019 12:53:29 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=HqWRPPSN; 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 S1732373AbfAKQy4 (ORCPT + 99 others); Fri, 11 Jan 2019 11:54:56 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:38252 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731598AbfAKQy4 (ORCPT ); Fri, 11 Jan 2019 11:54:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=yTgfkkdtMIoi23ux2f75q9TFNcJ9LY9AiM9jb/rIyCA=; b=HqWRPPSNy8nRRFaK5UH00k4DS 2xgbFuAUFbqf2EBzUiLY1rR4d8cCPNNCriTh6MI0hhhb9UnlITI4qhe4Oi96ON7Z/ldTsLrmC4ox7 6wsr6SPfg1NyR3JAJFSglyVVqWZcCDWvBMji+semi3UoGzsrVCH7fCFOzykKhMOB3NSHSAzLZo1wl 0N8GKtVJ3ZOrTTYxFKOEtfGian9qN23PL6qwyiS6s5vxqbYjUyy1yu4dYGoBaZVmt0GEDdATRX33L TMFx9zeG2QAlN1mxHaZO2TkXIEh7ZJ86d/IzAmXCbMdhrjkHYQZufagHJsUJ89KTXalIpXkszrAVT LwRxPgUCA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gi053-0005JS-Sf; Fri, 11 Jan 2019 16:54:49 +0000 Date: Fri, 11 Jan 2019 08:54:49 -0800 From: Matthew Wilcox To: James Bottomley Cc: Hannes Reinecke , "Gustavo A. R. Silva" , Hannes Reinecke , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] scsi: advansys: use struct_size() in kzalloc() Message-ID: <20190111165449.GG6310@bombadil.infradead.org> References: <20190104212209.GA15250@embeddedor> <05420a5c-c268-b87d-9d75-f5d18a4b7f7a@suse.de> <1547224903.2793.10.camel@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1547224903.2793.10.camel@linux.ibm.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 11, 2019 at 08:41:43AM -0800, James Bottomley wrote: > On Fri, 2019-01-11 at 16:46 +0100, Hannes Reinecke wrote: > > > - asc_sg_head = kzalloc(sizeof(asc_scsi_q->sg_head) > > > + > > > - use_sg * sizeof(struct asc_sg_list), > > > GFP_ATOMIC); > > > + asc_sg_head = kzalloc(struct_size(asc_sg_head, > > > sg_list, use_sg), > > > + GFP_ATOMIC); > > If you want ... > > Are we sure there's a benefit to this? It's obvious that the current > code is correct but no-one's likely to test the new code for quite some > time, so changing the code introduces risk. What's the benefit of > making the change in legacy drivers? Just because we have a new, shiny > macro doesn't mean we have to force its use everywhere. > > I would recommend we have a rational needs test: so run the coccinelle > script over all the drivers to find out where this construct is used, > but only update those that are actually buggy with the new macro. It's hard to tell whether they're buggy. The problem being defended against here is integer overflow. So can 'use_sg' ever get large enough that sizeof(asc_scsi_q->sg_head) + use_sg * sizeof(struct asc_sg_list) is larger than 4 billion? Probably not; I imagine there's some rational sane limit elsewhere that says "No more than 256 SG elements" or something. But I don't know without checking. Is there some device-specific ioctl where the user can specify 2^31 scatterlist entries and somebody forgot to check? This macro is a defense-in-depth strategy, so using it as widely as possible makes more sense than arguing about whether there are already adequate safeguards in place.