Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4030768rwo; Mon, 24 Jul 2023 22:39:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlHPNfOakosoeXqyxJVR0VbosIVBtcTKQc4iM4wmxgEW50LGx811Dymj9DGbHx5q5BVrrCQY X-Received: by 2002:a17:903:32c3:b0:1b0:f8:9b2d with SMTP id i3-20020a17090332c300b001b000f89b2dmr15752854plr.29.1690263551874; Mon, 24 Jul 2023 22:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690263551; cv=none; d=google.com; s=arc-20160816; b=bHyARCnOdpX3wKiGY+/qFbucTQ0FPMYxjeV0TJ6+YGvcNfTyOmkNAZGoYdUR0/IJ1a 8fqxgufb8eUdG0geWmWT4r4vZyuzzxLS3HsY5nTOAzA+/b5Iu6O7vCoWLe1Gwm/p2e36 X+QfqToUSl3+6pyVrM0Dyha1z5iJF3bWnhNayqZLeohxcN/nLlw6xtl0jUwedBrPXpiZ p0BBOm7fsof5e4Gid68ot+y3i5w1eeP4p8XHXYlK646Qm3uhPdRtV1bKRX+9d8xQYHgu l3AkAbom0dC6X62OPzdr7arjspnR1pZMcIN2QT5mQ0lTSOLLLZ+2JiyDRJovz9wSEdrI ObLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=GCp76nKWFRjLPkqDbChXZIXEfhN+VLo+a9Qs09xC07I=; fh=LMjoyxlZkd0AMGuFLBI8cBgG7LXdwymXN0BjgLPEm7I=; b=xNuoh04a2FyowtlFVYtMJqEeQ45Gpij02Yj2jSf18nVBDBqXgEuWCM5pp/Gkv1gzRY oxL7d6hrjm3TWwy5lrVjDYA6QYDCWEV53e8+/nhAcTlMn/sXWNm03PHpFaVC/qTP5i3u 0a5CrWEvco03+z3eSYl3yqKcZk7hIHeBtF5sBPJwPcO9r6Zel8UW4Hx+iDxwCiE77/AZ K/8ur+bxMyN0J1j3RgR+aOxDaAbBDkjCPbVXEqu5euThQ70MSCskZ6HGCyEtTlR75BEF n9Jb5h2IC45o5y6nLq5shnWLvjC8C4epuSBnkNskzynegQiibZM5+tvkFSKshYD+b/Yp Rexw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="h/GOZF3n"; 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 u13-20020a17090341cd00b001bb8df95094si6451139ple.509.2023.07.24.22.38.59; Mon, 24 Jul 2023 22:39:11 -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="h/GOZF3n"; 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 S229929AbjGYF0G (ORCPT + 99 others); Tue, 25 Jul 2023 01:26:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbjGYF0D (ORCPT ); Tue, 25 Jul 2023 01:26:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DC56A6; Mon, 24 Jul 2023 22:26:02 -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 12CE761503; Tue, 25 Jul 2023 05:26:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4FBAC433C8; Tue, 25 Jul 2023 05:26:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690262761; bh=bhUiI8tKngWF8aIibFJdKp8OVXvAKhVHmOkI8xo0b+M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=h/GOZF3nRKydRMlbSS1zKR5/kzUcRmnxUE/dpJ3Vg6fLVnTgZume0nNEMmM896KCE rGw82/0xS3USB5vxG0IZPRV2DsJWUqD/J1NznK9s9ieqsO7qk1NIRiNXTSz5hPphwX s2VJ/WcuLZ7tWFN58ySdUAyFuIHNpmRxasSsroRdIilwqkMXEQL5jotZQ9jxNRBQpl v+x66wIV8JJjjC6y7uRqS4aV9OIZff8nugABlaO7u4AVy8AamANsDAZ4kKos7hgo17 /DeJhhe2QgbdI1brCe1ENi8DCaYQxMFtHYrLylcRIUtIEv0wqy8Tk9q44FWcOKWq5f BJLgl0+oaN3Kg== Date: Tue, 25 Jul 2023 08:25:57 +0300 From: Leon Romanovsky To: Lin Ma , Jakub Kicinski Cc: jgg@ziepe.ca, markzhang@nvidia.com, michaelgur@nvidia.com, ohartoov@nvidia.com, chenzhongjin@huawei.com, yuancan@huawei.com, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1] RDMA/nldev: Add length check for IFLA_BOND_ARP_IP_TARGET parsing Message-ID: <20230725052557.GI11388@unreal> References: <20230723074504.3706691-1-linma@zju.edu.cn> <20230724174707.GB11388@unreal> <3c0760b5.e264b.1898a6368f8.Coremail.linma@zju.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3c0760b5.e264b.1898a6368f8.Coremail.linma@zju.edu.cn> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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, Jul 25, 2023 at 08:11:58AM +0800, Lin Ma wrote: > Hello Leon, > > > > > On Sun, Jul 23, 2023 at 03:45:04PM +0800, Lin Ma wrote: > > > The nla_for_each_nested parsing in function > > > nldev_stat_set_counter_dynamic_doit() does not check the length of the > > > attribute. This can lead to an out-of-attribute read and allow a > > > malformed nlattr (e.g., length 0) to be viewed as a 4 byte integer. > > > > 1. Subject of this patch doesn't really match the change. > > My bad, a stupid mistake. I will fix that and prepare another patch. > > > 2. See my comment on your i40e patch. > > https://lore.kernel.org/netdev/20230724174435.GA11388@unreal/ > > > > Yeah I have seen that. Just as Jakub said, empty netlink attributes are valid > (they are viewed as flag). The point is that different attribute has different > length requirement. For this specific code, the RDMA_NLDEV_ATTR_STAT_HWCOUNTERS > attribute is a nested one whose inner attributes should be NLA_U32. But as you > can see in variable nldev_policy, the description does not use nested policy to > enfore that, which results in the bug discussed in my commit message. > > [RDMA_NLDEV_ATTR_STAT_HWCOUNTERS] = { .type = NLA_NESTED }, > > The elegant fix could be add the nested policy description to nldev_policy while > this is toublesome as no existing nla_attr has been given to this nested nlattr. > Hence, add the length check is the simplest solution and you can see such nla_len > check code all over the kernel. Right, and this is what bothers me. I would more than happy to change nla_for_each_nested() to be something like nla_for_each_nested_type(...., sizeof(u32)), which will skip empty lines, for code which can't have them. Thanks > > > Thanks > > Regards > Lin