Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1251652imw; Tue, 5 Jul 2022 06:27:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tVsZFwnUscLoRTinIt24dV/p4OKBaWzT571DEbFwly2nMXCGADQCj5nLBjnc28HhnLyPci X-Received: by 2002:a17:907:a075:b0:72a:7508:c014 with SMTP id ia21-20020a170907a07500b0072a7508c014mr26543712ejc.176.1657027650424; Tue, 05 Jul 2022 06:27:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657027650; cv=none; d=google.com; s=arc-20160816; b=s45wQUSZmxLFbc0BnJ3GsZe5nMFQ5rkdpyFWpH9t1PS5sQGR1spXqgbLY3YNLPdFxo vs//JR+siXbtMZ6WfUUwF80VPdPtKvDSitIUOE821bHf9SZlOGssTwLcOMha2/CUhlAs FEI0awyeh+BptWLd3dw5oKn3siGAky2OiFvKsqogngj5dwhEHGHRa0PvieZYkTFD0dYg StEpofMurHNo1llS48XQHjL+ExgClQJ3uKp8ys8vzO18YDq2ulmcyJHsym99eHq2XU2y J4U+5IwQTWz+DQbNVTh8i2dvbQ9T/alPvjZyBxBp1Wf4mDtgwaKc5r1TIQyNGb2+1dpW hu3g== 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=Oi8/W5/lKQgNsGlvBligTzk+hvVU0ym45p2TfW9SM2M=; b=V77hMVd9nOXrZWd1uN4uZiOv8MrdoFOAgrVgwhuWJxch2F5iIXcX6EeW9ydFX8MK6j deqMhCKgxrisIxcEnCSbfR6kf9cNNQZhUyyBpYOxK50JdOfjTRueGS0PHNe3VwuAx0vf EzKa4zn2HtQ850ezqUpW9NVMtpqR7Q25PhGteOxbjmV7Fx8JP2RoFuobfwITFZCDcXdT AxHbNUyLnHAz5N/zu2kWPTiAQkl57MkDU2nzQWI3bAJ0OeCDEp8lMme5R49CgH3KFhxR OwoOHcWd2Q/mFJf8OsTxaXxUD1WmEJJBG4xSZwipwOAK55wpBJMA4qNOCX5AJtTdrPky Zu5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p9yw6pAI; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y12-20020a056402358c00b0042bd2c39f07si1485058edc.596.2022.07.05.06.27.05; Tue, 05 Jul 2022 06:27:30 -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=@linuxfoundation.org header.s=korg header.b=p9yw6pAI; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238030AbiGEM1G (ORCPT + 99 others); Tue, 5 Jul 2022 08:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237018AbiGEMSe (ORCPT ); Tue, 5 Jul 2022 08:18:34 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53A4E1A3A1; Tue, 5 Jul 2022 05:13:51 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id C5B7DB817D3; Tue, 5 Jul 2022 12:13:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D942C341C7; Tue, 5 Jul 2022 12:13:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657023228; bh=u2+qk0VaXt/xlaKih6IiscdsQz5E8o+kNEJq18d1LV4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p9yw6pAIvT33GawiFXnCJj9Qa0DZXw7OL8UgoCCgVUtdHbrsS+Ho5Yz7yKhxnZzUy fCOdQsh4o+5pbRHWeGZ6NP4WjYk9hvfaeKcc+MiIF22Oryj9vUQ5QV9C3+bXUlaxLM FOWSkUNHPEL3yRi/Dej+Crr17bbkK6R1wiI26DZY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Victor Nogueira , Jamal Hadi Salim , Jakub Kicinski Subject: [PATCH 5.15 42/98] net/sched: act_api: Notify user space if any actions were flushed before error Date: Tue, 5 Jul 2022 13:58:00 +0200 Message-Id: <20220705115618.782704663@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220705115617.568350164@linuxfoundation.org> References: <20220705115617.568350164@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=-7.8 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 From: Victor Nogueira commit 76b39b94382f9e0a639e1c70c3253de248cc4c83 upstream. If during an action flush operation one of the actions is still being referenced, the flush operation is aborted and the kernel returns to user space with an error. However, if the kernel was able to flush, for example, 3 actions and failed on the fourth, the kernel will not notify user space that it deleted 3 actions before failing. This patch fixes that behaviour by notifying user space of how many actions were deleted before flush failed and by setting extack with a message describing what happened. Fixes: 55334a5db5cd ("net_sched: act: refuse to remove bound action outside") Signed-off-by: Victor Nogueira Acked-by: Jamal Hadi Salim Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/sched/act_api.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -350,7 +350,8 @@ static int tcf_idr_release_unsafe(struct } static int tcf_del_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb, - const struct tc_action_ops *ops) + const struct tc_action_ops *ops, + struct netlink_ext_ack *extack) { struct nlattr *nest; int n_i = 0; @@ -366,20 +367,25 @@ static int tcf_del_walker(struct tcf_idr if (nla_put_string(skb, TCA_KIND, ops->kind)) goto nla_put_failure; + ret = 0; mutex_lock(&idrinfo->lock); idr_for_each_entry_ul(idr, p, tmp, id) { if (IS_ERR(p)) continue; ret = tcf_idr_release_unsafe(p); - if (ret == ACT_P_DELETED) { + if (ret == ACT_P_DELETED) module_put(ops->owner); - n_i++; - } else if (ret < 0) { - mutex_unlock(&idrinfo->lock); - goto nla_put_failure; - } + else if (ret < 0) + break; + n_i++; } mutex_unlock(&idrinfo->lock); + if (ret < 0) { + if (n_i) + NL_SET_ERR_MSG(extack, "Unable to flush all TC actions"); + else + goto nla_put_failure; + } ret = nla_put_u32(skb, TCA_FCNT, n_i); if (ret) @@ -400,7 +406,7 @@ int tcf_generic_walker(struct tc_action_ struct tcf_idrinfo *idrinfo = tn->idrinfo; if (type == RTM_DELACTION) { - return tcf_del_walker(idrinfo, skb, ops); + return tcf_del_walker(idrinfo, skb, ops, extack); } else if (type == RTM_GETACTION) { return tcf_dump_walker(idrinfo, skb, cb); } else {