Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2365860rwp; Fri, 14 Jul 2023 05:15:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlFwBj87sL2EStFih7rW2ANQM4XacR5NPxJyb23/lcoADWysgxPzLwBwa4+orfu881FmJtUn X-Received: by 2002:a17:903:1c2:b0:1b3:fb75:dd24 with SMTP id e2-20020a17090301c200b001b3fb75dd24mr4268178plh.48.1689336926463; Fri, 14 Jul 2023 05:15:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689336926; cv=none; d=google.com; s=arc-20160816; b=dqLrmWdWGfOaH5oic+HyZGwJOyp4kZ62fSWsGocvOByUn84zniNOOIyrQDnuIB7Huk HcFWEZf95KDXxAjzU7zyBsAgdxWrn7pejySDWER8TtsexFWbm5LeN0P3ffg23kR1xq92 lqp1TuPgxj830QdeDqWP6GnY7DQAJRxosTVEUS4TWveXl+WzgrsKWxbScfSa/5BgXwXy 4oVCxk4vTpfydlZB4/IHCj5hoNEy/0lMKpvsX7Y0taUgQodHk+s8Vjvso9+EXR1muI9e /tIcFTOQBjDC4+BGZqd/owPrVT5lCTQZF764xJ9dW/Fo4eWFH+CsWZCKyKVSE4QzIFRD yrhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=yyY3d4L/4TM3DnFCbW2Hi5z0uYaJ+hL5iiHAEEri3t4=; fh=Y0osi5esN/xAWkUDDPmt/V89rc6rE3XhGPgGwAie5w8=; b=efRlY0xPQOMsZnqTg0iqY1Dbj9fcYPjy/gieHS52Ve0INmiBu/gWhYX6KnFtAJZqJ1 mervsN7zjSaHPkQDDvWR55QuPd3ERLVPA0Qtd+qT9XC6pW4wMSdiAj3LlD3NUVV5XNME JhadwmFEs513N2UujgHI0T2PCE1u4kiZhqMDnh0x6mzC8UNZSxS1c4RNvhVYQPiAlcrb TCMkQ4WZ5QPEOwoK44cI/1DXfALWe157uqhFhN0xDcFzfqXBwkS2VbZH4P0J4oerQKRA l1GEP9U/T85wvFDmLFrqng9OazY2mrLYKOMhl/nvz+6xb5dsWnGH3NID1VBbEMsURER1 1gIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=ecuTDy+X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g1-20020a170902934100b001b9d5fb7fc8si6719021plp.101.2023.07.14.05.15.13; Fri, 14 Jul 2023 05:15:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=ecuTDy+X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235591AbjGNLmf (ORCPT + 99 others); Fri, 14 Jul 2023 07:42:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234797AbjGNLma (ORCPT ); Fri, 14 Jul 2023 07:42:30 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25CA935B8; Fri, 14 Jul 2023 04:42:05 -0700 (PDT) Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36EBfQVR032494; Fri, 14 Jul 2023 11:41:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=qcppdkim1; bh=yyY3d4L/4TM3DnFCbW2Hi5z0uYaJ+hL5iiHAEEri3t4=; b=ecuTDy+XzJU5u5e8juH4vbzpvZZ9VI8hI91uNEYUODpyzhq1bv4FmYF6R9oX9+D8+Icq nEY0jaBvPzpH3DopmoH7KPfBAjWGo03Dx3hRpMmeASBt42upzxE+o2714SY7hlEsxZaE bjrOhvTWg8xAKbTnElp8atMUeGGaMz3oYpIh7khG2TnI0fhC/Q425kP0PEjTdvDyUmcD wsMJXgGL0ITTQcfwdE85ut1c0e6HnbCmdkF3sFK7LEHOkvlAJ20xDtV33yEvldi54Awm yjksj+bBb/QoARDgCVVn+DSigH+rJ157s/cm8tWP9Vt3rBis7BVPCs1KyfAYXwg9DsFC kw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rtpu91k10-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Jul 2023 11:41:25 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36EBfOal003060 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Jul 2023 11:41:24 GMT Received: from [10.50.55.51] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Fri, 14 Jul 2023 04:41:21 -0700 Message-ID: Date: Fri, 14 Jul 2023 17:11:18 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH 1/5 v4] accel/qaic: tighten bounds checking in encode_message() To: Dan Carpenter , Jeffrey Hugo CC: Carl Vanderlip , Oded Gabbay , Jacek Lawrynowicz , Stanislaw Gruszka , , , , References: <9a0cb0c1-a974-4f10-bc8d-94437983639a@moroto.mountain> Content-Language: en-US From: Pranjal Ramajor Asha Kanojiya In-Reply-To: <9a0cb0c1-a974-4f10-bc8d-94437983639a@moroto.mountain> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: UIehr1-6VSs5Egc2FYBdlPUW24Ca8XOs X-Proofpoint-ORIG-GUID: UIehr1-6VSs5Egc2FYBdlPUW24Ca8XOs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-14_06,2023-07-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 priorityscore=1501 mlxlogscore=743 clxscore=1011 adultscore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307140105 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/11/2023 1:50 PM, Dan Carpenter wrote: > There are several issues in this code. The check at the start of the > loop: > > if (user_len >= user_msg->len) { > > This check does not ensure that we have enough space for the trans_hdr > (8 bytes). Instead the check needs to be: > > if (user_len > user_msg->len - sizeof(*trans_hdr)) { > > That subtraction is done as an unsigned long we want to avoid > negatives. Add a lower bound to the start of the function. > > if (user_msg->len < sizeof(*trans_hdr)) > > There is a second integer underflow which can happen if > trans_hdr->len is zero inside the encode_passthrough() function. > > memcpy(out_trans->data, in_trans->data, in_trans->hdr.len - sizeof(in_trans->hdr)); > > Instead of adding a check to encode_passthrough() it's better to check > in this central place. Add that check: > > if (trans_hdr->len < sizeof(trans_hdr) > > The final concern is that the "user_len + trans_hdr->len" might have an > integer overflow bug. Use size_add() to prevent that. > > - if (user_len + trans_hdr->len > user_msg->len) { > + if (size_add(user_len, trans_hdr->len) > user_msg->len) { > > Fixes: 129776ac2e38 ("accel/qaic: Add control path") > Signed-off-by: Dan Carpenter Reviewed-by: Pranjal Ramajor Asha Kanojiya