Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2141803rdb; Mon, 20 Nov 2023 03:18:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOBL1bP9XMeWb7biImlGb00qebXcEIu/cJUOmRBRG1f708CYOCh6B2qSwzz7gdVyoRzbEg X-Received: by 2002:a9d:7f9a:0:b0:6cd:4fc8:3efc with SMTP id t26-20020a9d7f9a000000b006cd4fc83efcmr1830356otp.19.1700479097652; Mon, 20 Nov 2023 03:18:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700479097; cv=none; d=google.com; s=arc-20160816; b=BvDsLoqMuBfbXRIKaqSdTnn3xx45lzjO0iss1ocgysMaqV95afJ1V6CiTUcXy6V7zW mlvF67aM/Q2olkTAZR0CPm270qVwJgsL2niDayKiwBR90Cr2LW/3m1gw2bNY7OIU2+w6 T4j+HqLM1RGr6RR8E5vQDHjpnXcLDSHV5ss+SVSxeDr6HX6l6mDMRITp9GZaOBBgHakE KoC5CHsZehgxFX0iK3firmstVvMAae7PY07F7JURbtYc7Yo0ro6OmNEzb51zCLkXaa6o AVx06XGu4unPTm5b6BwjjIOUo4pnCPedUDOZwOKA6ABxNUkaEDxKBBfjwcnyjk00OEyX fo1A== 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; bh=2KloICT5j+d9Aur4QJo//yNlB3U4vL7kyIh6Vl9i1KM=; fh=cnUf80AJk8Pf/8x/6NeZMkSWDGNiOsTDkaIz73b8wgk=; b=U8RdUjR/qA2O5wPEmg4AgN5cDQEYMt+Xl1rCEriOjcSAlZWiUXL1UmZWO1xuwzkVHC 3todITeAvc8c4rj6OtOisANvKy4FBL8tP/iDVNHwxhS/PjbmevgCHrUTa+4KhZ88gx1d dUzRkNVjKlaq8nFVWHN6z3z8VV9vgwlpcGsLBv5bXR338RtKjZdJJVRX0zsDKLCEUv1S vLnfBoU4IWuCmVTndNUq9b6ekTxYLdsVRpHTj9Mu4X1lJ+OxBVwHl/CFeXyKX/5yCJmS jjg0CE+ckiPEJnEX/bcDXGvWBf1p765JhUQWGr3MjFhogHyImSJvlUPqlQfyrn/owO2m eGug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id q36-20020a631f64000000b0059f0cebd04csi7643512pgm.722.2023.11.20.03.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:18:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id D719D804476F; Mon, 20 Nov 2023 03:18:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233482AbjKTLRF (ORCPT + 99 others); Mon, 20 Nov 2023 06:17:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233110AbjKTLQj (ORCPT ); Mon, 20 Nov 2023 06:16:39 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CED9F10E4; Mon, 20 Nov 2023 03:16:10 -0800 (PST) X-UUID: beef4f8ad89d4ec4931d5c243f55d868-20231120 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.32,REQID:412260c0-b0b1-4902-84f2-0ed738ad25c1,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-5 X-CID-INFO: VERSION:1.1.32,REQID:412260c0-b0b1-4902-84f2-0ed738ad25c1,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:5f78ec9,CLOUDID:e38adb72-1bd3-4f48-b671-ada88705968c,B ulkID:231120180427G1WW4E38,BulkQuantity:4,Recheck:0,SF:24|17|19|44|64|66|3 8|102,TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:40,QS:nil,BEC:nil, COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: beef4f8ad89d4ec4931d5c243f55d868-20231120 X-User: chentao@kylinos.cn Received: from [172.21.13.26] [(116.128.244.171)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 2086711540; Mon, 20 Nov 2023 19:15:59 +0800 Message-ID: <69a4bc75-d1a7-482d-9848-26fdc1de78b4@kylinos.cn> Date: Mon, 20 Nov 2023 19:15:58 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] net: sched: Fix an endian bug in tcf_proto_create Content-Language: en-US To: Simon Horman , Pedro Tammela Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, kunwu.chan@hotmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20231117093110.1842011-1-chentao@kylinos.cn> <16c758c6-479b-4c54-ad51-88c26a56b4c9@mojatatu.com> <20231120100417.GM186930@vergenet.net> From: Kunwu Chan In-Reply-To: <20231120100417.GM186930@vergenet.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 20 Nov 2023 03:18:07 -0800 (PST) Hi Simon, Thanks for your reply. For a lot of newcomers who aren't proficient in this part of the code, like me, it might be confusing what is the correct endien and width of a protocol. In response to your question, I wonder if it is necessary to implement a unified checking mechanism with a strict parameter validation for all invocation parameters? For example, add an input parameter to the 'tcf_proto_create' to represent the endien and width of the protocol, and check the validity of the input parameter at the beginning of the function. I don't have a good idea of how to make sure that the right type is used in the call path. This is just my personal opinion, welcome to discuss. On 2023/11/20 18:04, Simon Horman wrote: > On Fri, Nov 17, 2023 at 09:06:45AM -0300, Pedro Tammela wrote: >> On 17/11/2023 06:31, Kunwu Chan wrote: >>> net/sched/cls_api.c:390:22: warning: incorrect type in assignment (different base types) >>> net/sched/cls_api.c:390:22: expected restricted __be16 [usertype] protocol >>> net/sched/cls_api.c:390:22: got unsigned int [usertype] protocol >>> >>> Fixes: 33a48927c193 ("sched: push TC filter protocol creation into a separate function") >>> >>> Signed-off-by: Kunwu Chan >>> --- >>> net/sched/cls_api.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c >>> index 1976bd163986..f73f39f61f66 100644 >>> --- a/net/sched/cls_api.c >>> +++ b/net/sched/cls_api.c >>> @@ -387,7 +387,7 @@ static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol, >>> goto errout; >>> } >>> tp->classify = tp->ops->classify; >>> - tp->protocol = protocol; >>> + tp->protocol = cpu_to_be16(protocol); >>> tp->prio = prio; >>> tp->chain = chain; >>> spin_lock_init(&tp->lock); >> I don't believe there's something to fix here either > > Hi Pedro and Kunwu, > > I suspect that updating the byte order of protocol isn't correct > here - else I'd assume we would have seen a user-visible bug on > little-endian systems buy now. > > But nonetheless I think there is a problem, which is that the appropriate > types aren't being used, which means the tooling isn't helping us wrt any > bugs that might subsequently be added or already lurking. So I think an > appropriate question is, what is the endien and width of protocol, and how > can we use an appropriate type throughout the call-path?