Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3113235pxm; Mon, 28 Feb 2022 12:17:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxqpxX2LpllSNFzfJqB1F3lO0WYuZwk5WeSOYNmA4RIfd+9LgH3YDU7oYgo+x/FgZQ0kEJC X-Received: by 2002:aa7:982d:0:b0:4e1:56d4:1e78 with SMTP id q13-20020aa7982d000000b004e156d41e78mr23614183pfl.24.1646079431751; Mon, 28 Feb 2022 12:17:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079431; cv=none; d=google.com; s=arc-20160816; b=gcfqlWIzBBKyNkbWZWu9NkkossYYOhcQFdJm3Xm2nAQW8HwdruCXk9ntvUHN/KNZvT TO5mXU11DXu/3vSVVUZv0jiPERj1YDWJKEDAC+SNe9V1ZTsECqBsqgZG8QMyR2FaN9xq ESXtak72T27xGSuE707PtvasN+HknEsVFie7dBXoQ83tce/xub7R9rnQhF57r958hB/4 QIjWet29hNCAvy80bRtpCveKiN4S1i5QFZZIOiyQquD8K0GhsG0lrklz+tZMJXqTyPFQ iEjHP0bWjUKlY57gp52jIya/kF/acDdezGQpFN5QgSqeU1Ilf/rqG5OrkTTy7jB1LMqp F8CA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=p1k7DPX5CaDGMAr8MvjSqmWC/Pz7GaqCAegA4MsNAwQ=; b=ob2uZvNowgT6Sm8kgQLauv3uXbSSurlmTA8Td7Uy5d6YLjG43MqZNUFV5Hh1voh5mk WezetURHUn1gNrI3SQ2YacB6HRdOxHc9Dup9AO1NNtfjxKh6ulGa6Ji9Y8zjX6COoZWj FA4qLtquJrcshvPjThbCodkhwVtvjF2gCxpqMp9hx1hDV3hVQBqyBMjkFh4XCNIxR+z8 ssJRLLv4NJCB5uEjSi7c1sqfqU1c69+W9L7s8Zs2ePF4/oL+lHT8HYZI/NE6RTji05jR c+9hLd+e7LNBq9wJPVpERRk1XyTaFhVmoSG5xe8ufXJ7GJ/Ly+DP0jfcX918yQ8B51uy LwRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z1xg9TOl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t13-20020a17090a5d8d00b001b990f5228bsi349435pji.118.2022.02.28.12.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:17:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z1xg9TOl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A270D6A03E; Mon, 28 Feb 2022 11:38:28 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232977AbiB1SHj (ORCPT + 99 others); Mon, 28 Feb 2022 13:07:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240439AbiB1SDd (ORCPT ); Mon, 28 Feb 2022 13:03:33 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B7B771CB6; Mon, 28 Feb 2022 09:47:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 89BCA60748; Mon, 28 Feb 2022 17:47:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 929E5C340E7; Mon, 28 Feb 2022 17:47:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646070432; bh=XSLKRkij1uXAIPZeU+vR3idzKH3jAVHBKW7vVMbPZpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z1xg9TOl1Tl7mJyggkxEta+WOt7NX3jMyxIZbXHpCFGgH8ExN4fSEQZLy1n1ntBnV BFgPvQPMv1Bey7+6s16TNwljAjJ3JagjXo0o1bX4AsnTgOAzQVo7V31r308rlOsJBX FJgw8nPdHkBmVVt+KW7LpctBKs8DPhjXQpb3L6Zs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Felix Maurer , Daniel Borkmann , Yonghong Song , John Fastabend Subject: [PATCH 5.16 057/164] bpf: Do not try bpf_msg_push_data with len 0 Date: Mon, 28 Feb 2022 18:23:39 +0100 Message-Id: <20220228172405.333864395@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172359.567256961@linuxfoundation.org> References: <20220228172359.567256961@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Felix Maurer commit 4a11678f683814df82fca9018d964771e02d7e6d upstream. If bpf_msg_push_data() is called with len 0 (as it happens during selftests/bpf/test_sockmap), we do not need to do anything and can return early. Calling bpf_msg_push_data() with len 0 previously lead to a wrong ENOMEM error: we later called get_order(copy + len); if len was 0, copy + len was also often 0 and get_order() returned some undefined value (at the moment 52). alloc_pages() caught that and failed, but then bpf_msg_push_data() returned ENOMEM. This was wrong because we are most probably not out of memory and actually do not need any additional memory. Fixes: 6fff607e2f14b ("bpf: sk_msg program helper bpf_msg_push_data") Signed-off-by: Felix Maurer Signed-off-by: Daniel Borkmann Acked-by: Yonghong Song Acked-by: John Fastabend Link: https://lore.kernel.org/bpf/df69012695c7094ccb1943ca02b4920db3537466.1644421921.git.fmaurer@redhat.com Signed-off-by: Greg Kroah-Hartman --- net/core/filter.c | 3 +++ 1 file changed, 3 insertions(+) --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2711,6 +2711,9 @@ BPF_CALL_4(bpf_msg_push_data, struct sk_ if (unlikely(flags)) return -EINVAL; + if (unlikely(len == 0)) + return 0; + /* First find the starting scatterlist element */ i = msg->sg.start; do {