From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B782A1101; 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> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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.