Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5155664rwb; Mon, 31 Jul 2023 19:56:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlHQYQDt9dtAV06moyV8zYLv7VYDLz5BsWfmmgNs4ZTyDfSaX1b0GgIuzmmFqwMdmhRfmLRK X-Received: by 2002:a05:6a20:3d05:b0:125:dd60:957a with SMTP id y5-20020a056a203d0500b00125dd60957amr14411528pzi.26.1690858578501; Mon, 31 Jul 2023 19:56:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690858578; cv=none; d=google.com; s=arc-20160816; b=lGUAdJkmUnnP92SINU/M4YW2FViQ1q/q5sRfcaC4ORw6/fnchyliA9nKLiHNw+rtqB mKPNw6VPdQNKXfqE0USX5GmKE1b9qPvb3BW8e0lm9+ja3yb323XBAA3Mzppp540KZGtV 3dAnOCipm+Sc1CbU+8m8N3UMKNDmDK0dYUD8imeYTlsRqRvQRxHW6qxI5hC5twhij2w3 JDZVKtokFtfrWgw34Gyus3N7l4HF7l2ELU+nuYouI0HBoGHsbONVw0oAlUpoPIDdV6fN tIZ0IkLvjiaQu523WSB+M6MUm8Eds1nq/a3s+1e0rKjdk9Yio+DPjcF78iyyvAlQnvfz mM4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=afhPXJVUWUcWmdIG62yqPU22nm2LJ2HS6xWZUpZ68pk=; fh=JGddd+1ZAVv2aKP7wpJ1x5mL+L5op5Cl5wxNPEFdfX4=; b=UHUuP4kbEL4Ft4ulggPaW0wHi9Q3M2KkIKHegIEIRnTX6KyW03U8lzLP9O0Oln+5rg pJnas4mgLS1Fx+aJLee26qBkWDGmfi/SU6/cIWgKYX2olrj+7kEiCLkG18vbBW3OCRRG WLs0/5NZUM5S/szf/mImC55siSepfv/G0mbZX1yaWloe9q0wlMoRQRyPwzjyQ19zKrpY y4bmSFg0GE8Zy9OJalYAlenDpvj4hRFWM7PB/SvWWpbXBt43Q/0TgycDPCnkavptBniu F50NEgbaeWaHIRP+tdf7EQFYl5f83EuGzjf/noOEznpQU/bSmO26BjWDBN97sPfQ7VZY iAZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KAG52lTM; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a632c01000000b005518971fccbsi7993272pgs.712.2023.07.31.19.56.05; Mon, 31 Jul 2023 19:56:18 -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=@kernel.org header.s=k20201202 header.b=KAG52lTM; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232113AbjHACbX (ORCPT + 99 others); Mon, 31 Jul 2023 22:31:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232102AbjHACbW (ORCPT ); Mon, 31 Jul 2023 22:31:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47288E65; Mon, 31 Jul 2023 19:31:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D74FD6139D; Tue, 1 Aug 2023 02:31:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F803C433C7; Tue, 1 Aug 2023 02:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690857080; bh=mTxd6HdQzFWXD+l9R8aNLIJTw4K0Wg96Ajxe6Cwzwpw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KAG52lTMe9zgens46rA1eqv/cVT1kaIN46yTHYubtyBonBbMQC7xVE46a34uehmga 31kWSsZKowpkD2MbkHQGzvlDaG+VeKKeumaCEJFWx1l38kPGdAx445eNnJf9W1AQYI vl1/r2x6mzXlfvj/rLlL6MMd6XlCwD/U6U1THCHc1VAWGL2xf5wHhSbZVLSwvRh++6 qvWYTtlQ7AU1tja7v7JykjmZIrgOWlpI+j7yAb/QqsX6cQwhYaaajdO0Sm2Xevw57D uta6SqTz1Cg2sKs9BKsapSAlYej0MqzS9/ntVSPABQsROacNQHjl3FFg0CgrRS4Rfe B8hTP27zKtI8g== Date: Mon, 31 Jul 2023 19:31:18 -0700 From: Jakub Kicinski To: "Lin Ma" Cc: davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, fw@strlen.de, yang.lee@linux.alibaba.com, jgg@ziepe.ca, markzhang@nvidia.com, phaddad@nvidia.com, yuancan@huawei.com, ohartoov@nvidia.com, chenzhongjin@huawei.com, aharonl@nvidia.com, leon@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org Subject: Re: [PATCH net v1 1/2] netlink: let len field used to parse type-not-care nested attrs Message-ID: <20230731193118.67d79f7b@kernel.org> In-Reply-To: <38179c76.f308d.189aed2db99.Coremail.linma@zju.edu.cn> References: <20230731121247.3972783-1-linma@zju.edu.cn> <20230731120326.6bdd5bf9@kernel.org> <38179c76.f308d.189aed2db99.Coremail.linma@zju.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Tue, 1 Aug 2023 10:00:01 +0800 (GMT+08:00) Lin Ma wrote: > > > However, this is tedious and just like Leon said: add another layer of > > > cabal knowledge. The better solution should leverage the nla_policy and > > > discard nlattr whose length is invalid when doing parsing. That is, we > > > should defined a nested_policy for the X above like > > > > Hard no. Putting array index into attr type is an advanced case and the > > parsing code has to be able to deal with low level netlink details. > > Well, I just known that the type field for those attributes is used as array > index. > Hence, for this advanced case, could we define another NLA type, maybe > NLA_NESTED_IDXARRAY enum? That may be much clearer against modifying existing > code. What if the value is of a complex type (nest)? For 10th time, if someone does "interesting things" they must know what they're doing. > > Higher level API should remove the nla_for_each_nested() completely > > which is rather hard to achieve here. > > By investigating the code uses nla_for_each_nested macro. There are basically > two scenarios: > > 1. manually parse nested attributes whose type is not cared (the advance case > use type as index here). > 2. manually parse nested attributes for *one* specific type. Such code do > nla_type check. > > From the API side, to completely remove nla_for_each_nested and avoid the > manual parsing. I think we can choose two solutions. > > Solution-1: add a parsing helper that receives a function pointer as an > argument, it will call this pointer after carefully verify the > type and length of an attribute. > > Solution-2: add a parsing helper that traverses this nested twice, the first > time to do counting size for allocating heap buffer (or stack > buffer from the caller if the max count is known). The second > time to fill this buffer with attribute pointers. > > Which one is preferred? Please enlighten me about this and I can try to propose > a fix. (I personally like the solution-2 as it works like the existing parsers > like nla_parse) Your initial fix was perfectly fine. We do need a solution for a normal multi-attr parse, but that's not the case here.