Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6113552rdb; Thu, 14 Dec 2023 08:37:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKsvidzaJ8uByr2Uko+uSv67h94JUzXUgDOKilwIqatE+TGVomjOpsoqancR3Tmd8P38oB X-Received: by 2002:a17:90b:2282:b0:28b:16dc:d616 with SMTP id kx2-20020a17090b228200b0028b16dcd616mr877196pjb.33.1702571855995; Thu, 14 Dec 2023 08:37:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702571855; cv=none; d=google.com; s=arc-20160816; b=jF2MFxb9TdzEE6hbzbGUu4o8ZXOUR63+B+NIdoX6WqvmM6QcEFwR08Ut6fdYzAmgT/ amCYeQZNqoVpBZf1/4dbcY1ygD7CDNJRa35SDcO1KiQX/fTeOKxaKstUIsoEe+hJlCdj Wk/Bte6irEd0lX0qIJ2VbH8vYQ0k0RIkarAJHVEW/hYlOxVg3YRMp8z8fG2s/a4Bvqy7 wHk97nkxiWlcrx9iFguACUviqvGcpoevZbbqFc7CkwhWr6p3CvFGZgEwpf78Y4jCz0fW 6Yc2276wYTDKsl+9n0jpPgcmoEAcdOVhDJFWe35pda+ZdgYxm0JZIu4E8joejtmdeFZw NzDg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ytGugjo0G0b+BPvqCI62+RFEO79iMDy6vjEWkwFFqNo=; fh=zAC+IambVEfbj7QuDB3+T+j51eLmztGLyvWTW4QPtyc=; b=pbZdF4gwU4hgIeLdG3NqfqgKA/QBAGs8PABuKEJiTNZti7AdTjp2Mj5bGCehaxa0Ml 6lfPwEpoGMq0WuEXzd4INFAouO8cWMV1DmVE8AZVWuxjKtjtXUeCIOzj4O1iCMnQG2if 4ptuAPWwHVhecoGOYCz1DkycG84HeEzKJVbJJqTB0nWzkcMhbDPBmxOTDPw7TvEtgQ7+ YovrR0R1Nw+k2/WBmj4WrAeLqE6Az0OMGZvE3IginPcM0msJizC3qesC3DOkwBg4Nju1 Vx3oLhpbtU9AQpe9mvmae3AS3yjIUCw8Dk005Obv45SCUydFrRYpqU5Q7u5KizufldyS VpzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GCJi+iSK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id w6-20020a17090a8a0600b00286b47270b3si12781450pjn.151.2023.12.14.08.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 08:37:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GCJi+iSK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 5ACD18347B46; Thu, 14 Dec 2023 08:37:33 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230031AbjLNQhL (ORCPT + 99 others); Thu, 14 Dec 2023 11:37:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbjLNQhJ (ORCPT ); Thu, 14 Dec 2023 11:37:09 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 680AD11B for ; Thu, 14 Dec 2023 08:37:15 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6d26eef7438so208009b3a.0 for ; Thu, 14 Dec 2023 08:37:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702571835; x=1703176635; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=ytGugjo0G0b+BPvqCI62+RFEO79iMDy6vjEWkwFFqNo=; b=GCJi+iSKpjqkkNglOX7WPB7/8KITsstZp0kPuEDUMvK0hDP8P5OlgM3DvnT1kZ+Ht3 qD4TydnzFsFH4nERqqpXyGSovEHKbC72lFZVKreji5eX4kcfOz5hXq9m14gDXYNVVeji /lRcyO7zCIbtqFnCH78mjwSjhqOdfo3BNPNoA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702571835; x=1703176635; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ytGugjo0G0b+BPvqCI62+RFEO79iMDy6vjEWkwFFqNo=; b=aBfyOqlV/ZlCULv2Jy5AFBgJBrj1LOD8AQf1LY7+2HVASMF5OApC4Yzg5cS5c/zdky OXi2YCYxQFjp7Lorc+meuiwXmxFx9gp8oxgPP8XHqxWB/5Ug7W4JZ1BWxstgVVWIPEcW bxX8LwaRRYnfxpaT8NBl9gXNuHNCr8pJl3cFlNb+udPE0xYE4xkBnMrnTQrMBgKWq6UN R1Sc36NZk84dSsl1NMJ5K0/BtY1ZMtaKDdFiSC5c4LZEqSYz1WPUxCnNxXx2xROyMYe6 /66+5mf8PMXlE99pojBKPyfaP6iU1zm2UYrPOc+basgFX3s0rEO8zd43CebawshFjL1F suzg== X-Gm-Message-State: AOJu0YyflhtZcnPELqc+Qf5oRDzn26q1vn+QpyP74l4IuuHg5tN4kkvv AkyqVE58XpzUfnGkK8rJIsk6Iw== X-Received: by 2002:a05:6a00:2d9e:b0:6cd:fda4:b57c with SMTP id fb30-20020a056a002d9e00b006cdfda4b57cmr12902654pfb.15.1702571834799; Thu, 14 Dec 2023 08:37:14 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id gx4-20020a056a001e0400b006cbb71186f7sm11945039pfb.29.2023.12.14.08.37.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 08:37:14 -0800 (PST) Date: Thu, 14 Dec 2023 08:37:13 -0800 From: Kees Cook To: "Gustavo A. R. Silva" Cc: Benson Leung , Guenter Roeck , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] platform/chrome: Fix -Warray-bounds warnings Message-ID: <202312140836.5AB528D54F@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 14 Dec 2023 08:37:33 -0800 (PST) On Wed, Mar 29, 2023 at 07:54:02PM -0600, Gustavo A. R. Silva wrote: > GCC-13 (and Clang) does not like having a partially allocated object, > since it cannot reason about it for bounds checking. > > Notice that the compiler is legitimately complaining about accessing > an object (params, in this case) for which not enough memory was > allocated. > > The object is of size 20 bytes: > > struct ec_params_vbnvcontext { > uint32_t op; /* 0 4 */ > uint8_t block[16]; /* 4 16 */ > > /* size: 20, cachelines: 1, members: 2 */ > /* last cacheline: 20 bytes */ > }; > > but only 16 bytes are allocated: > > sizeof(struct ec_response_vbnvcontext) == 16 > > In this case, as only enough space for the op field is allocated, > we can use an object of type uint32_t instead of a whole > struct ec_params_vbnvcontext (for which not enough memory is > allocated). > > Fix the following warning seen under GCC 13: > drivers/platform/chrome/cros_ec_vbc.c: In function ‘vboot_context_read’: > drivers/platform/chrome/cros_ec_vbc.c:36:15: warning: array subscript ‘struct ec_params_vbnvcontext[1]’ is partly outside array bounds of ‘unsigned char[36]’ [-Warray-bounds=] > 36 | params->op = EC_VBNV_CONTEXT_OP_READ; > | ^~ > In file included from drivers/platform/chrome/cros_ec_vbc.c:12: > In function ‘kmalloc’, > inlined from ‘vboot_context_read’ at drivers/platform/chrome/cros_ec_vbc.c:30:8: > ./include/linux/slab.h:580:24: note: at offset 20 into object of size 36 allocated by ‘kmalloc_trace’ > 580 | return kmalloc_trace( > | ^~~~~~~~~~~~~~ > 581 | kmalloc_caches[kmalloc_type(flags)][index], > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 582 | flags, size); > | ~~~~~~~~~~~~ > > Link: https://github.com/KSPP/linux/issues/278 > Signed-off-by: Gustavo A. R. Silva FWIW, I think this is the right change that disrupts the code the least. Reviewed-by: Kees Cook -Kees -- Kees Cook