From patchwork Fri Apr 12 22:42:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 1084982 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44gtFB1lp6z9s71 for ; Sat, 13 Apr 2019 08:42:21 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 3E0E9179A; Fri, 12 Apr 2019 22:42:18 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 9D8011757 for ; Fri, 12 Apr 2019 22:42:17 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id BF8F2860 for ; Fri, 12 Apr 2019 22:42:16 +0000 (UTC) X-Originating-IP: 66.170.99.95 Received: from sigill.benpfaff.org (unknown [66.170.99.95]) (Authenticated sender: blp@ovn.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id CB654C0009; Fri, 12 Apr 2019 22:42:13 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Fri, 12 Apr 2019 15:42:09 -0700 Message-Id: <20190412224209.3101-1-blp@ovn.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff , fuzhantao Subject: [ovs-dev] [PATCH] classifier: Avoid use-after-free due to classifier_destroy(). X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: fuzhantao classifier_destroy() didn't postpone destroying subtables enough. Signed-off-by: Ben Pfaff --- I need a Signed-off-by from fuzhantao. lib/classifier.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/classifier.c b/lib/classifier.c index edb40c89c608..595d2fdf54c3 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -1468,6 +1468,19 @@ miniflow_get_map_in_range(const struct miniflow *miniflow, uint8_t start, return map; } +static void +subtable_destroy_cb(struct cls_subtable *subtable) +{ + int i; + + for (i = 0; i < subtable->n_indices; i++) { + ccmap_destroy(&subtable->indices[i]); + } + cmap_destroy(&subtable->rules); + + ovsrcu_postpone(free, subtable); +} + /* The new subtable will be visible to the readers only after this. */ static struct cls_subtable * insert_subtable(struct classifier *cls, const struct minimask *mask) @@ -1530,12 +1543,11 @@ insert_subtable(struct classifier *cls, const struct minimask *mask) return subtable; } -/* RCU readers may still access the subtable before it is actually freed. */ +/* RCU readers may still access the subtable before it is actually freed. + * double postpone for subtable to avoid use-after-free. */ static void destroy_subtable(struct classifier *cls, struct cls_subtable *subtable) { - int i; - pvector_remove(&cls->subtables, subtable); cmap_remove(&cls->subtables_map, &subtable->cmap_node, minimask_hash(&subtable->mask, 0)); @@ -1545,11 +1557,7 @@ destroy_subtable(struct classifier *cls, struct cls_subtable *subtable) ovs_assert(cmap_is_empty(&subtable->rules)); ovs_assert(rculist_is_empty(&subtable->rules_list)); - for (i = 0; i < subtable->n_indices; i++) { - ccmap_destroy(&subtable->indices[i]); - } - cmap_destroy(&subtable->rules); - ovsrcu_postpone(free, subtable); + ovsrcu_postpone(subtable_destroy_cb, subtable); } static unsigned int be_get_bit_at(const ovs_be32 value[], unsigned int ofs);