From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63A13C433EF for ; Thu, 28 Apr 2022 14:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=h/r4cZj/46QpdtWOrvmrQpT4zAXbQexSv/n4mTwZsXc=; b=oXtiH91Fy/XQcj YmspPRUkXvAfGVfjF71KqpJV4qRQllTLWh4p8LGemuNJrCScVBebsc5ff8zX0znRU8G4lEc06ftGB PITthdUcv5cBJHvcn1ECvqUbvtfXQsv7spBraLjXTj+TcHdncPJA2Sakw1CdTSvtA/u+6dDjsI5Ry Gsulg25naeNtLVfOgXJz5ZhfzEMvE5jU1yMEu1lBhzhPOMh6syZjA3zFzKxgj1AmJKQwB0AJNxq0X F38QmLU3K3KAS21+EspN0imw/3e+f3KJg0ypbryep6Sf2+8G4vlWB8ycwt4YxKNycW8xQNOuuBEAl y6013qB/mHQ9K+1IPxZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk4us-007Oex-M6; Thu, 28 Apr 2022 14:14:48 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk4jm-007Il7-DF for linux-arm-kernel@lists.infradead.org; Thu, 28 Apr 2022 14:03:20 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BB6BF1474; Thu, 28 Apr 2022 07:03:16 -0700 (PDT) Received: from e120937-lin (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7BD7D3F5A1; Thu, 28 Apr 2022 07:03:15 -0700 (PDT) Date: Thu, 28 Apr 2022 15:03:05 +0100 From: Cristian Marussi To: Sudeep Holla Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.quinlan@broadcom.com, Jonathan.Cameron@huawei.com, f.fainelli@gmail.com, etienne.carriere@linaro.org, vincent.guittot@linaro.org, souvik.chakravarty@arm.com Subject: Re: [PATCH 04/22] firmware: arm_scmi: Validate BASE_DISCOVER_LIST_PROTOCOLS reply Message-ID: References: <20220330150551.2573938-1-cristian.marussi@arm.com> <20220330150551.2573938-5-cristian.marussi@arm.com> <20220428100729.qlzl5lkkn2r5u3ra@bogus> <20220428135504.lt3bjq4sz7uktca6@bogus> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220428135504.lt3bjq4sz7uktca6@bogus> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220428_070318_600467_25337C47 X-CRM114-Status: GOOD ( 29.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Apr 28, 2022 at 02:55:04PM +0100, Sudeep Holla wrote: > On Thu, Apr 28, 2022 at 02:45:07PM +0100, Cristian Marussi wrote: > > On Thu, Apr 28, 2022 at 11:07:29AM +0100, Sudeep Holla wrote: > > > On Wed, Mar 30, 2022 at 04:05:33PM +0100, Cristian Marussi wrote: > > > > Do not blindly trust SCMI backend server reply about list of implemented > > > > protocols, instead validate the reported length of the list of protocols > > > > against the real payload size of the message reply. > > > > > > > > Fixes: b6f20ff8bd9 ("firmware: arm_scmi: add common infrastructure and support for base protocol") > > > > Signed-off-by: Cristian Marussi > > > > --- > > > > drivers/firmware/arm_scmi/base.c | 21 +++++++++++++++++++++ > > > > 1 file changed, 21 insertions(+) > > > > > > > > diff --git a/drivers/firmware/arm_scmi/base.c b/drivers/firmware/arm_scmi/base.c > > > > index f279146f8110..c1165d1282ef 100644 > > > > --- a/drivers/firmware/arm_scmi/base.c > > > > +++ b/drivers/firmware/arm_scmi/base.c > > > > @@ -189,6 +189,9 @@ scmi_base_implementation_list_get(const struct scmi_protocol_handle *ph, > > > > list = t->rx.buf + sizeof(*num_ret); > > > > > > > > do { > > > > + size_t real_list_sz; > > > > + u32 calc_list_sz; > > > > + > > > > /* Set the number of protocols to be skipped/already read */ > > > > *num_skip = cpu_to_le32(tot_num_ret); > > > > > > > > @@ -202,6 +205,24 @@ scmi_base_implementation_list_get(const struct scmi_protocol_handle *ph, > > > > break; > > > > } > > > > > > > > + if (t->rx.len < (sizeof(u32) * 2)) { > > > > + dev_err(dev, "Truncated reply - rx.len:%zd\n", > > > > + t->rx.len); > > > > + ret = -EPROTO; > > > > + break; > > > > + } > > > > + > > > > + real_list_sz = t->rx.len - sizeof(u32); > > > > + calc_list_sz = ((loop_num_ret / sizeof(u32)) + > > > > + !!(loop_num_ret % sizeof(u32))) * sizeof(u32); > > > > > > Any reason this can't be (loop_num_ret - 1) / sizeof(u32) + 1 ? > > > > > > > At first sight could be fine with your easier version BUT what if loop_num_ret > > is returned as zero ? > > > > real_list_sz should be ZERO length and calc_list_sz > > > > im my version: > > > > calc_list_sz = ((0/4) +!!(0%4)) * 4 ===>> 0 > > > > while in the simplified one gets calculated wrong: > > > > calc_list_sz = (0-1)/4 + 1 ====> 1 > > > > ...moreover being both loop_num_ret and calc_list_sz unsigned I am even > > not so sure about implicit casting messing things up evenm more :D > > > > So I sticked to the more convoluted approach :D > > > > ....Have I missed something else ? > > > > Right, but shouldn't we break if it 0 much earlier. It must not happen with > your new logic and even if it does, wouldn't it be better to break earlier ? > Fine for me. Thanks, Cristian _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel