Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp522521rwb; Tue, 25 Jul 2023 20:58:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlEUUZrCWC1wKpI8aprmGBhWQt7veomj9iD1aBfhw+RxEgt4wElVULbZEE1ndzDZKtq1DCSV X-Received: by 2002:a05:6512:54b:b0:4f7:6017:8fb with SMTP id h11-20020a056512054b00b004f7601708fbmr492594lfl.26.1690343902757; Tue, 25 Jul 2023 20:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690343902; cv=none; d=google.com; s=arc-20160816; b=BAqRKLF2jo20KBf9F9/IOj0lpdeYiil98TNunWrw0j5pNMMSJTVnzhIHHt3C2qGKeZ 8JkifbgH20m2iNAneY3YsIYALMimjNiEYwCNrSRObmAM3yCSRIz9w6/kOWJjR5DPPuA2 cwss+ZjXPtPRb2bSC7wh9787b6vx9ey70nPfMVwD2waa+uR8Ees5aXExh1DO1KlHlaYw z7JHDfqsOfFmjMLZbhawC5uvuC+YBWehuDvq3O0tRHp7tr8d1/e4u7quFeLs9jke+KFT YDVW5NXU45KJcsQsaC97pU6pG1iapIHlH+5lIP2FP6Ke3Kf6iagnUGPUMN0my6E1Z0hT hakw== 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=z5xrE8DhnrE3WWTJh7QQiIfwChu2X8Vn5H/qvPVFtqE=; fh=y3TV8hk6hQ4iXgIoh8oDXf3mwx3hu6pixD4TYJIjjlE=; b=b9YDgLCq6rq+4rcb7oGKvBrsUb77Lbum2Pts50mI8kLsTne2VeVbZ4baH11wFrkA/Y ouQP1VnA592ctwuKq+SyPh60saGHPlwcEiIQ38kSkki6j7zfQ8bW1gv5nQp/X+ppA2qQ huT4tQr/cVq8wIOUuMGeTnjb6kqUD7ZVeJQHZk/ahsl4VDy/SJWJjxuRVZ5LZ2f+DZGI rB3aHgwvNPpBJ80nhD1AG31MhGKtcRNinQ2ZHsvq7q8FX/4mmGCMneSgO57YB4an2OG6 vDQJbh95EeAHI1Cz3cre9x/2FlwNlkia6y/Hc96+x9zgGsdMpaU0fBmc8/5oxidYcc32 O7Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OOjHtuoB; 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 x3-20020aa7d6c3000000b005223789d9e9si3397976edr.382.2023.07.25.20.57.58; Tue, 25 Jul 2023 20:58:22 -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=OOjHtuoB; 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 S229834AbjGZDLr (ORCPT + 99 others); Tue, 25 Jul 2023 23:11:47 -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 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, 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.