Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp3698029rwo; Mon, 24 Jul 2023 15:27:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlHrrV1bm7D1KgnATTOPtXuNcqSRTqjrWOATw3XsHaHeWAhZKjeG4Xv9mUUsGN+6z31s+vYn X-Received: by 2002:a17:90a:d57:b0:267:909f:3719 with SMTP id 23-20020a17090a0d5700b00267909f3719mr11581870pju.19.1690237679536; Mon, 24 Jul 2023 15:27:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690237679; cv=none; d=google.com; s=arc-20160816; b=ViYQxs4qiGCOizNhR6DRrhEFDdQoKrkebBvcP5VhvL116OJ6HgaS/qOfgB4gmB2SB7 WY08GbfcFtIPwG1PpCNUU8ClMIeSmeWD5QmNuhh+ITk5xXqZ5TXSsw/vZCKcLupiNx7V sLQnGL/2xKyDdKgWvMJYkyFNQYRI+yzxc4U/W+2sOYRKuoAYgpPQnnyto+KFMsOvTnVC HZl1CrUucHewf7lsYBe3lDkJkM85JZaZNtuQr2Oe8nlret3P8g1vHlnNBifJG++7zsMX UZrEA2ZNt46Jz3RbJPI51iAp2vSsPCfFsh5Fh9LzPRU5IMdPPNQtPHC27WNq3vUbkncn SFEg== 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=MJUtOAhHssQzqgwCawqpr9MUpOB9yBufp5Lq4Uyzt5Q=; fh=vzq4Saek0o/eXOCHhSl4nrOjRLeizufkB+Y5aoEswUY=; b=l9GkbRm3Icy2k1WbAIdFiL/gbHfW5O+i5QLTWGdOyvHV63DxWZI8UM7/UVwbpRlypT yTobJNydqouzWfFKCIpQypSmNOCpP5b+s/o9vBv9JE7BjDtsimLecHSNGNajGrbL5YjZ qDbA8h4TsI5Ek7DSm6vtPs4L4MFQCNaQa7efRzH8BMACqu+e7ri2qLPXVrqeO+ThUW2i 2R4kCxXGGEZhMVT06XO0haKy7UUkeRMbXI8TGZdVFef5W+efdR+c/n0OgWE9n5HADmlt i0PKfpgrFisFPZWvfbZj5OvHtsV6XK7V79q29Fd+Ltf9SqaLeHdNqB1y/wrLYopQeHAF IRlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Dr7Xp5wn; 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 t19-20020a17090a951300b00263e8027e64si5495542pjo.138.2023.07.24.15.27.47; Mon, 24 Jul 2023 15:27:59 -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=Dr7Xp5wn; 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 S230259AbjGXWPM (ORCPT + 99 others); Mon, 24 Jul 2023 18:15:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229578AbjGXWPK (ORCPT ); Mon, 24 Jul 2023 18:15:10 -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 3E38410EC for ; Mon, 24 Jul 2023 15:15:10 -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) server-digest SHA256) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BD17661456 for ; Mon, 24 Jul 2023 22:15:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65425C433C8; Mon, 24 Jul 2023 22:15:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690236908; bh=5xU8tBKog8sD1JT305O0sYBJ6mz8EHv0yDqZFATvuNA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Dr7Xp5wnxDZjFEfx+9tLIR9i1MgWSC/hswijslOzxPFHq9W87Z22xM9hkc0K3vLAP 535QD2ZHp8H6dMsCMjtoKd7buT93O2EG0PYYq5oP7PzSYdR9F06z2WV33nxLLK+tRe YyxFhBZdYX4f/GfwsfYB1BnUwCRMjtwmb+E+dppsrvTJeNKzCpvo5c9oxr2lA8VVCg qKxUa2v/dRoWOUMsZ2WQgV7hwUnYdoCAB+1yjRpTnFPSAaxRIoyjH6TimHB8X6Zuq4 DlwzGY69RwYl19StgzX/UPl0XyknSrEtRWV0cV4R9Ar4sm0NYIA/F+yUJmvGES3+Vt x9dudg89G0hqw== Date: Mon, 24 Jul 2023 15:15:07 -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, andrii@kernel.org, void@manifault.com, houtao1@huawei.com, laoar.shao@gmail.com, inwardvessel@gmail.com, kuniyu@amazon.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH v1] bpf: Add length check for SK_DIAG_BPF_STORAGE_REQ_MAP_FD parsing Message-ID: <20230724151507.6b725396@kernel.org> In-Reply-To: <20230723075452.3711158-1-linma@zju.edu.cn> References: <20230723075452.3711158-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=-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 Sun, 23 Jul 2023 15:54:52 +0800 Lin Ma wrote: > diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c > index d4172534dfa8..6f1afbb394a6 100644 > --- a/net/core/bpf_sk_storage.c > +++ b/net/core/bpf_sk_storage.c > @@ -511,6 +511,11 @@ bpf_sk_storage_diag_alloc(const struct nlattr *nla_stgs) > if (nla_type(nla) != SK_DIAG_BPF_STORAGE_REQ_MAP_FD) > continue; > > + if (nla_len(nla) < sizeof(map_fd)) { > + err = -EINVAL; > + goto err_free; > + } You can move this check earlier, when the attributes are getting counted. That way we can avoid the alloc/free on error.