From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA17CEB64DD for ; Wed, 26 Jul 2023 03:11:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230270AbjGZDLt (ORCPT ); Tue, 25 Jul 2023 23:11:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbjGZDLq (ORCPT ); Tue, 25 Jul 2023 23:11:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BCA71BF8 for ; Tue, 25 Jul 2023 20:11:45 -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 D9EC4601D6 for ; Wed, 26 Jul 2023 03:11:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9968CC433C7; Wed, 26 Jul 2023 03:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690341104; bh=9Upzi3S02vKTUvKJdNd22YEHdE2llnbz3XXAiMSuNQE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=OOjHtuoBNOKGC4Cyl5+apIy5ejwGjm9BJ7VcnFMgxtPGfvvNZJe/ZX/G/1B8Z4O2x eQOAs2Kp/LYfxkavQsjHHjqeqmQMFBWaOSHZyF3g58ifceVEphQL0CWIbMJg5yix7O sV3Nakdf8ebHoYjkgZL3xmQFkb0EYnxcj1xjjUKTsK+MdgcRbL7/iR+GDM6/maUP+N uhqmu0yaUEv2hQEPKz5yM2akmGRqPFuGwwlrWCB2g4VUSNJ1CKrv237SPUKq2mLR5f pdS2eVt5vTQGqGiuDApscRr5VzxEIat80QMf97lEdTGdpWeA/5zsZz9uLNlld8yhsa t/+5LIi+hmeRw== Date: Tue, 25 Jul 2023 20:11:42 -0700 From: Jakub Kicinski To: Lin Ma Cc: davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, ast@kernel.org, martin.lau@kernel.org, yhs@fb.com, void@manifault.com, andrii@kernel.org, houtao1@huawei.com, inwardvessel@gmail.com, kuniyu@amazon.com, songliubraving@fb.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH v2] bpf: Add length check for SK_DIAG_BPF_STORAGE_REQ_MAP_FD parsing Message-ID: <20230725201142.593ae606@kernel.org> In-Reply-To: <20230725023330.422856-1-linma@zju.edu.cn> References: <20230725023330.422856-1-linma@zju.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 25 Jul 2023 10:33:30 +0800 Lin Ma wrote: > The nla_for_each_nested parsing in function bpf_sk_storage_diag_alloc > does not check the length of the nested 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. > > This patch adds an additional check when the nlattr is getting counted. > This makes sure the latter nla_get_u32 can access the attributes with > the correct length. > > Fixes: 1ed4d92458a9 ("bpf: INET_DIAG support in bpf_sk_storage") > Suggested-by: Jakub Kicinski > Signed-off-by: Lin Ma Reviewed-by: Jakub Kicinski Those who parse manually must do checks manually. It is what it is.