Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp914309pxj; Wed, 2 Jun 2021 15:05:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxR3RJougYS/kZS063UpDhmo8j7gOYhN9vhcsL/SRfx17dy93L4i9rc+YfSngPS3cXiDrbl X-Received: by 2002:a17:906:3485:: with SMTP id g5mr5848242ejb.174.1622671508744; Wed, 02 Jun 2021 15:05:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622671508; cv=none; d=google.com; s=arc-20160816; b=Dc+CPsAu1ssPzaR45D4jOBVMDoPNerw3Itsa34wAy6YWD/k5ZI2YcPl12dek2/EuHh 3nm4M2UNMGuz6T7IYk5hC6JQSnJIisT19EiB++5QWxShIZBotCcDG7/nkqOk0N3cOmmr 7TkD2N059ywe0/rIM+ujeSxSdBrxVHHhCBD7FOIjHw2Sog1Y6jmJ7U/Vg6ExnIqHEa4e JagFOPhglzauAh/WY4EDWWNiPLwrPxhU1sPPrjXglGlyize6qPZlJ+CGzv4okOqW//Y/ pG9j+pii0wfC7CrHFFQUk8rBZU57Npt9RQlOfrFIFukO2a7NyKa5Sw4OLsxwLx+ipBbg 0xqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject:dkim-signature; bh=QGxXXmCFwyQE+vVNSEra/v2uZBYm6bBxxjB0/bpHJj0=; b=r4gZBlg8K+6GSB+8oI077XuRD7UrMEjDAuRzCWcyTadrbEujLMeOmncKlTm3lX2J0I CTk0dyzhSmCL05+LXw9nznWb16Hhxu/quggATty6YxC6D/fkOBuDr1EISW+EPhTDN7KG 3hcOpYnXZRliibLNwPDTNXhkvUbLMFZ6oCBtbGi+vMlhAG1i5h/6i56yWjbFbcT1lrYA FXiVbX9JeEqRU7NODoJioJbDpWuVrgLKbBzpEjli3mHAwtqzpN0kRv19vJEAZMDiLoAT bdG0kXY9x5x3f8LIvIzhiPsscPtXjDS7CS4ImOkmmsb20G2Y3XgVYzNVjyZi3vNjyHxX jo3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b="K5w/is1y"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bv2si785007ejb.450.2021.06.02.15.04.41; Wed, 02 Jun 2021 15:05:08 -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=fail header.i=@embeddedor.com header.s=default header.b="K5w/is1y"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229626AbhFBWDI (ORCPT + 99 others); Wed, 2 Jun 2021 18:03:08 -0400 Received: from gateway33.websitewelcome.com ([192.185.146.195]:22770 "EHLO gateway33.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbhFBWDI (ORCPT ); Wed, 2 Jun 2021 18:03:08 -0400 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 45BC75AB7B for ; Wed, 2 Jun 2021 17:01:24 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id oYvUlWVhSVBxyoYvUlznkR; Wed, 02 Jun 2021 17:01:24 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:References:Cc:To:From:Subject:Sender :Reply-To: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=QGxXXmCFwyQE+vVNSEra/v2uZBYm6bBxxjB0/bpHJj0=; b=K5w/is1y6OWG4J4JsHJi+SeTNn KC5+nKnTyg0qCm7TTgmHdYyHcGZSDwvSN3rxxEkZpbQb4uMQQmA89McPTAA2ge9a6wpzh6KGYi+Jt H6CMyO0Rz5ZDD4aDVpqOrZ6vVdNYfOByVCuZEkZO55B9XEqvLMnphnrJJsF8aK6tR8QenuKt9AOoQ xtpQZL44B8QYYAvqUZlosIbkrRFFjeYp6WWykaOWBuwwtlCtn0cvc9j7ie99NBGG2myMMC47LASOv SFcWek5q4WzBsT5OLQahxjUBdwW6RSnIxN0531p+usneuWK2IZ61ii6knQ4RE4zTq6AltdFXuIXXq S3S9cuKw==; Received: from 187-162-31-110.static.axtel.net ([187.162.31.110]:52554 helo=[192.168.15.8]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1loYvQ-00061U-Lg; Wed, 02 Jun 2021 17:01:20 -0500 Subject: Re: [PATCH][venus-for-next-v5.14] media: venus: hfi_cmds: Fix packet size calculation From: "Gustavo A. R. Silva" To: Kees Cook , "Gustavo A. R. Silva" Cc: Stanimir Varbanov , Andy Gross , Bjorn Andersson , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20210601184616.GA23488@embeddedor> <202106021254.39A1561075@keescook> Message-ID: <113fd896-464c-6aef-215a-a53ac6103a62@embeddedor.com> Date: Wed, 2 Jun 2021 17:02:25 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 187.162.31.110 X-Source-L: No X-Exim-ID: 1loYvQ-00061U-Lg X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 187-162-31-110.static.axtel.net ([192.168.15.8]) [187.162.31.110]:52554 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 9 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/2/21 15:34, Gustavo A. R. Silva wrote: > > > On 6/2/21 14:55, Kees Cook wrote: >> On Tue, Jun 01, 2021 at 01:46:16PM -0500, Gustavo A. R. Silva wrote: >>> Now that a one-element array was replaced with a flexible-array member >>> in struct hfi_sys_set_property_pkt, use the struct_size() helper to >>> correctly calculate the packet size. >>> >>> Fixes: 701e10b3fd9f ("media: venus: hfi_cmds.h: Replace one-element array with flexible-array member") >>> Signed-off-by: Gustavo A. R. Silva >>> --- >>> BTW... it seems that a similar problem is present in >>> https://lore.kernel.org/linux-hardening/20210211001044.GA69612@embeddedor/ >>> and that is what is causing the regression. I will send v2 of that >>> patch, shortly. Thanks. >>> >>> drivers/media/platform/qcom/venus/hfi_cmds.c | 8 ++++---- >>> 1 file changed, 4 insertions(+), 4 deletions(-) >>> >>> diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.c b/drivers/media/platform/qcom/venus/hfi_cmds.c >>> index 11a8347e5f5c..c86279e5d6e8 100644 >>> --- a/drivers/media/platform/qcom/venus/hfi_cmds.c >>> +++ b/drivers/media/platform/qcom/venus/hfi_cmds.c >>> @@ -27,7 +27,7 @@ void pkt_sys_idle_indicator(struct hfi_sys_set_property_pkt *pkt, u32 enable) >>> { >>> struct hfi_enable *hfi = (struct hfi_enable *)&pkt->data[1]; >>> >>> - pkt->hdr.size = sizeof(*pkt) + sizeof(*hfi) + sizeof(u32); >>> + pkt->hdr.size = struct_size(pkt, data, 2) + sizeof(*hfi); >> >> I think this should be "1" not "2". >> >> (i.e. there is a single "data" item, followed by an entire *hfi (which >> starts immediate after data[0]). > > Yeah; I see your point. Here I just wanted to preserve the exact same size > as the original code, which turns out has a "benign" off-by-one issue. And the reason why I say it's a "benign" off-by-one (which is actually off-by-four-bytes) issue is because of this piece of code: drivers/media/platform/qcom/venus/hfi_venus.c: 864 static int venus_sys_set_idle_message(struct venus_hfi_device *hdev, 865 bool enable) 866 { 867 struct hfi_sys_set_property_pkt *pkt; 868 u8 packet[IFACEQ_VAR_SMALL_PKT_SIZE]; 869 int ret; 870 871 if (!enable) 872 return 0; 873 874 pkt = (struct hfi_sys_set_property_pkt *)packet; 875 876 pkt_sys_idle_indicator(pkt, enable); 877 878 ret = venus_iface_cmdq_write(hdev, pkt, false); 879 if (ret) 880 return ret; 881 882 return 0; 883 } IFACEQ_VAR_SMALL_PKT_SIZE at line 868 is of size 100, which is greater than sizeof(*pkt) + sizeof(*hfi) + sizeof(u32); in the original code: drivers/media/platform/qcom/venus/hfi_cmds.c: 26 void pkt_sys_idle_indicator(struct hfi_sys_set_property_pkt *pkt, u32 enable) 27 { 28 struct hfi_enable *hfi = (struct hfi_enable *)&pkt->data[1]; 29 30 pkt->hdr.size = sizeof(*pkt) + sizeof(*hfi) + sizeof(u32); 31 pkt->hdr.pkt_type = HFI_CMD_SYS_SET_PROPERTY; 32 pkt->num_properties = 1; 33 pkt->data[0] = HFI_PROPERTY_SYS_IDLE_INDICATOR; 34 hfi->enable = enable; 35 } -- Gustavo > I'll fix it up and respin. > > Thanks! > -- > Gustavo