Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1826507rdb; Wed, 31 Jan 2024 10:09:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEd9erUsXEvUMCFfEgwc/osU7AT4Zbt3e+jth0Dudb/5BOetb5ZoK8EFKATIq+VJjYB8Jws X-Received: by 2002:a05:651c:a0a:b0:2d0:4c36:8cbf with SMTP id k10-20020a05651c0a0a00b002d04c368cbfmr2084472ljq.16.1706724543446; Wed, 31 Jan 2024 10:09:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706724543; cv=pass; d=google.com; s=arc-20160816; b=BO7OVwdmsec7taVznbi+TDSQTZwEBkn6e9sSPXuObQCJ9hWdGTc6YBCPlX45YSoSB7 CBVKXpEkZxPtcQrNZvMo3M6iEyArc1L9VVjO9Y5lKzMheJ7tscA5B447zeOIzYmbmV67 M8h1Zu4NZl4mV6izNjbKrL7V2jKRo0avEHI9wgr5vxKdK3pRF3RX8coEsNY3Trg7aKji 3AQGMd0UZ3CTqc0cFXmdDxXmRgQ7LuARQm4tk503d93YCd960aJRUU63S5FP4lN24W1I wZNjI4otVTgeP0rYxL2C5aYuxXOLiduvj166CW7S2xNWPrCpk2M5noFfcrcYDqWDru9B K6HQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=K988A/nCvY7++Ns1OTEX4DSJbSLU9SSwyLn1Bd2jd5E=; fh=xpVDs3OW4xwo+bPPUuf/ETQMj1ojnXCRLkafMYvm234=; b=sCq8VaB9ImM7l2bh9G+M/rSpOzxlE7bjn0k2tJrrPxhublTDlfKbd9bv/5H6uadnM1 GuX3MatYca4hpnfPGaAqUBmzzhMCBBaDl47MwK7yX8+C1LWtNA4/eT6ZpILOdmSP/Kgf OIrRWCglPBpV01p8QRg42rckLlci/uSC+n6LglN92JjGA4FuXUZ/BOaiXH0EOypK8Y8M cYpCnKnJzD1Kc0+AQZRSP8e/SJjXFUUpqKT2ANhkg3rtVLJ9CsyvwyQJXUbwjFIW8g7k ztEbFxPPRBefZG5uOQWbHQCnexIzOhkwVMThVt4s2B/kV7ess0U5X3w07PwFeNYRtXEf bj/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=cnQcIM6T; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-46949-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46949-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=1; AJvYcCUdWzB/NORAlsxmnqCr0kZzE4xxef4LPv5dQicteMqxcSeVP6I7RhwLfFkXE3jIZfwNjDu/ZTSqtmNCXFyTFAD5UrU+xZzNDTrbJWyJ/g== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z20-20020a05640235d400b0055ee9d31227si3868968edc.415.2024.01.31.10.09.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 10:09:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46949-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=cnQcIM6T; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-46949-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46949-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EFED21F24F01 for ; Wed, 31 Jan 2024 18:09:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CAADC135412; Wed, 31 Jan 2024 18:08:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="cnQcIM6T" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 166F712DDB6; Wed, 31 Jan 2024 18:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706724522; cv=none; b=r6HmkHn5fJcvfixAFW25IzFjQrxYil86h/P6MWQO7wUWfvZFQqfCaHQnfSigydEMwFCUZDIuI4m9EdMK696wu5Lq4OU110h2DFIOnUMZVz6cF6msQdYi1ugbjLVAZIqQZgfxLqaVv0/WT4bRWEUk8NDC1jAEmr19A8l0ApTNinA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706724522; c=relaxed/simple; bh=qo55Ya1zrMut/Ge9/eEA9XjoOSaLw2btqX7Iod2jOuk=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=M15XzhLLwR/P0Na+tNCqp0b+OW+n8xNIdlXo4Ts+1R0QX7XcwaPTwizFEOzHdp4nap6dIclBhH3d3EtaAv+yPd9z/4lUvEstqaTMkd1fnwK2Q9BzmNawUD9wQfOKhLYGGerl6Es08ejQOxm1a/D0oQkeAKzxt6Fgt3k4xC1AEhI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=cnQcIM6T; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 40VHvOti024450; Wed, 31 Jan 2024 18:08:36 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=K988A/nCvY7++Ns1OTEX4DSJbSLU9SSwyLn1Bd2jd5E=; b=cn QcIM6TKbIyhDlbdSrs4mqm0RnHiSd+J1nvGHEEA+MzfmerKheIyh1R6hhUa4JlxK /Sys+DfUFEhke51NpUur1ICx6EvvR5YEJ1EowAK0kAH7Bjz2I1s08Vuqb5Ql3C52 YxAeSTbBi4dUyqzvoDiUGJY0bNzXtqqq+XgE9hMwClfeFn5l5YOmqwz089o6flZf 9iRqDPjxu6l0xu6G5ggI0talwMJQ00G88BmcId01IYnUcpzsXDMSNj7glUHs2+po qkd5QZxofbn6JdHYdwkHycPlFi6oA7KGYi6Gkzqi2jrispHKUG7Jq5k884u0PEFi PFBomjTsJKO+zDNsX/Ug== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vypaq0rke-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 Jan 2024 18:08:35 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 40VI8Z4f014192 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 Jan 2024 18:08:35 GMT Received: from [10.216.50.212] (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.40; Wed, 31 Jan 2024 10:08:31 -0800 Message-ID: <47bf719c-a5c1-473b-9fa0-8cad84f0721c@quicinc.com> Date: Wed, 31 Jan 2024 23:38:26 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] usb: gadget: ncm: Avoid dropping datagrams of properly parsed NTBs To: =?UTF-8?Q?Maciej_=C5=BBenczykowski?= CC: Greg Kroah-Hartman , Hardik Gajjar , , , , , References: <20240131150332.1326523-1-quic_kriskura@quicinc.com> Content-Language: en-US From: Krishna Kurapati PSSNV In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) 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-ORIG-GUID: z4UMFwPYct1wO3N9o3unHjTu6_3PUFNS X-Proofpoint-GUID: z4UMFwPYct1wO3N9o3unHjTu6_3PUFNS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-31_10,2024-01-31_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxlogscore=826 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401190000 definitions=main-2401310140 On 1/31/2024 10:33 PM, Maciej Żenczykowski wrote: >> >> diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c >> index ca5d5f564998..8c314dc98952 100644 >> --- a/drivers/usb/gadget/function/f_ncm.c >> +++ b/drivers/usb/gadget/function/f_ncm.c >> @@ -1338,11 +1338,17 @@ static int ncm_unwrap_ntb(struct gether *port, >> "Parsed NTB with %d frames\n", dgram_counter); >> >> to_process -= block_len; >> - if (to_process != 0) { >> + >> + if (to_process == 1 && >> + (block_len % 512 == 0) && >> + (*(unsigned char *)(ntb_ptr + block_len) == 0x00)) { > Hi Maciej, > I'm unconvinced this (block_len % 512) works right... > imagine you have 2 ntbs back to back (for example 400 + 624) that > together add up to 1024, > and then a padding null byte. > I think block_len will be 624 then and not 1024. > > perhaps this actually needs to be: > (ntp_ptr + block_len - skb->data) % 512 == 0 > > The point is that AFAICT the multiple of 512/1024 that matters is in > the size of the USB transfer, > not the NTB block size itself. > Ahh !! So you mean, since this comes because the host doesn't want to send packets of size wMaxPacketSize on the wire, we need to consider the length of data parsed so far to be checked against 512/1024 and not block length. But either ways, the implementation in the patch also the same thing in a different way right ? Process all NTB's present iteratively and while doing so, check if there is one byte left. So if there are multiple NTB's mixed up to form a packet of size 1024, even then, both the logics would converge onto the point where they find that one byte is left. >> + goto done; >> + } else if (to_process > 0) { >> ntb_ptr = (unsigned char *)(ntb_ptr + block_len); > > note that ntb_ptr moves forward by block_len here, > so it's *not* always the start of the packet, so block_len is not > necessarily the actual on the wire size. > Apologies, I didn't understand this comment. By moving the ntb_ptr by block length, we are pointing to the (last byte/ start of the next NTB) right as we are fixing in [1] ? >> goto parse_ntb; >> } >> >> +done: >> dev_consume_skb_any(skb); >> >> return 0; >> -- >> 2.34.1 >> > > But it would perhaps be worth confirming in the MS driver source what > exactly they're doing... > (maybe they never even generate multiple ntbs per usb segment...) > Yes they do and we made a fix for that in [1]. > You may also want to mention in the commit message that 512 comes from > USB2 block size, and also works for USB3 block size of 1024. > Sure. Will update the commit message accordingly. [1]: https://lore.kernel.org/all/20230927105858.12950-1-quic_kriskura@quicinc.com/ Regards, Krishna,