Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2671943rwp; Fri, 14 Jul 2023 09:27:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlEbheFaKfZCXxzDlSsuyXYtatUhnUZCkgqVmzzia5A4VKxSe+Yr+AkD+IOpxyLhNqK/3N9N X-Received: by 2002:a17:906:74dc:b0:994:1808:176b with SMTP id z28-20020a17090674dc00b009941808176bmr3672400ejl.6.1689352065172; Fri, 14 Jul 2023 09:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689352065; cv=none; d=google.com; s=arc-20160816; b=ym6ZnEcd4fEbV5bYB9sq02weDN+rs4HQazYwtuyte+uiyFe7rFVv2g75PFmrsNZeuQ SFnCwUVoe3+ohcgoyWHxggF04qHr7U4ecBznG6MXz8XVQfC3PRK1avBXYx/JemS9H72p 9SCCplh4/5cySM6q5ugiYYcBE+2hlSwS+6J7yHqucdMe9c5u+L3De5r7V/A7Ek5Ei1bI 0lxxB1qszwEKHsbM4K8NrQIjhJZCu6qQPQq7rqU7V9Kxypq/tJvpdrQd3UZUoqLqrP2M 2QKmXEiS0jmrpw/VRljn6ZRXenyi8/t9VTUyAI8ja3EGrjXwTbIYjJcH2sfLL5JrRjXL QL2g== 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 :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=ARDC8b208So03WCyLILljaM4pNxF9LTaUqV36KJV0QQ=; fh=hHdNMsSNF/ZmNs20s9lmRsrVvGO1GfLQiNXsb/hsNR4=; b=BgTjKEXrPDVcS/Kxyj+0yAwvZGu2lgt7W1m9VxWqZOpjfghJaSrcCzr5FlNgX9Gofd 63QyxnxBUd2KCzKtwLHpWzRZZipWY5/9vqjBm99W6nDKFWanR7dwvdeqwJExkLwhTG/z Ek8Atf6gv1Yv75enr5Rtntv9gIHZrH+6na94xWtMECCm0DybtxhAY1aLG4AXh4A9uPnV wRb56OAp0s0G1UNZy75rwJM61y2rsRKHGF29RXSBiY/LodJBcmAuEitzf/EHMIBgzJQm m4nwEJtfqFstGQzbRYbmmD7Zr/CdAzshpxoj/LjbSi7gqbcUWEEEFF/EgP651Ib7qLRq XvkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="kT/RRIZW"; 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 f12-20020a17090624cc00b00992c243f101si1025676ejb.854.2023.07.14.09.27.21; Fri, 14 Jul 2023 09:27:45 -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="kT/RRIZW"; 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 S236012AbjGNQCy (ORCPT + 99 others); Fri, 14 Jul 2023 12:02:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235396AbjGNQCw (ORCPT ); Fri, 14 Jul 2023 12:02:52 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52E65359F; Fri, 14 Jul 2023 09:02:51 -0700 (PDT) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36ECBGFn009535; Fri, 14 Jul 2023 16:02:33 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=ARDC8b208So03WCyLILljaM4pNxF9LTaUqV36KJV0QQ=; b=kT/RRIZWUcAHvKjxhHRZUhci1G1qN8ICPfFySW/y5tTpPKNgudqC8r47HrOeYODGHPxP ouKuLW7KoGSnubQwzXrLZv+RphHzuLTXgBLFZrdCU7FOtOYjvzVFoWIUMXL5/wxjwXAm p2F33AbVt9TrjezN9IPn7ADQ/3MaDsaFEQ/lFyCf8orS18jOS4McU6RUVBLHEAlg77Vf UcgDGiEL0pNYAzhviRXUGnf3NLmoalJ3zpEeig+Dp//VLQXwQirSKEMv3pg4RX8PFgYj uXfsEDc4SdLs/BsJZS/kY3z6Ye7JtI9Aulnh02JrakXdMgT4UmU9JC9AgpTgKOtBjx6R Bg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rtpuht3ev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Jul 2023 16:02:33 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36EG2WAn024410 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Jul 2023 16:02:32 GMT Received: from [10.226.59.182] (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 09:02:31 -0700 Message-ID: <51f205ad-eceb-d664-272f-d80cba828f21@quicinc.com> Date: Fri, 14 Jul 2023 10:02:28 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH 1/5 v4] accel/qaic: tighten bounds checking in encode_message() Content-Language: en-US To: Pranjal Ramajor Asha Kanojiya , Dan Carpenter CC: Carl Vanderlip , Oded Gabbay , Jacek Lawrynowicz , Stanislaw Gruszka , , , , References: <9a0cb0c1-a974-4f10-bc8d-94437983639a@moroto.mountain> From: Jeffrey Hugo In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit 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: BZZOwy2uZOhHnZCYPG3Xtd_Or2hzX-5n X-Proofpoint-ORIG-GUID: BZZOwy2uZOhHnZCYPG3Xtd_Or2hzX-5n 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_07,2023-07-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 mlxlogscore=778 spamscore=0 malwarescore=0 bulkscore=0 impostorscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307140146 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/14/2023 5:41 AM, Pranjal Ramajor Asha Kanojiya wrote: > > > 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 > Applied to drm-misc-fixes -Jeff