Received: by 10.223.185.116 with SMTP id b49csp1057702wrg; Fri, 23 Feb 2018 11:08:06 -0800 (PST) X-Google-Smtp-Source: AH8x227qTGfl8yrbAWfhOG2vOC5zkv+g2OtJE2Xhzt082+i3r3IsN9gDBc3FNq//+90cO3SB9xPR X-Received: by 2002:a17:902:bb81:: with SMTP id m1-v6mr2591608pls.71.1519412886250; Fri, 23 Feb 2018 11:08:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519412886; cv=none; d=google.com; s=arc-20160816; b=DTxGZpWIAkzS5P0VNWC/DlFMBu24IF1GL8w9szKETgWrUs/WFZCxQ5xqnHYol1pWQc 6KZqFHlBF1mBzJ0SyaIQGXAMyXq9fSe7zXKo0u+E03bxtxZKFX3XIWwRiAMXqVk6RBxf Yqw1pU3ipnf13GHqiC5aDQqH/Ii9+bWxohwu+FK0yC4j17wGg066rl/hZKyCcNit3lmc Se/js+qEWllvf4C9+1/4Bq9Txj8aRGk1AJgLil4u1Z4x4NEzMjUC57VpJj2Ygg3aThCP AgO7Fn9c5C6Hp50jZtvf21oN9HngKGV6suIYIPUWkaG6z76CahDR2bA0g2WGnVCTAEnO 8TPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=t++N3aqvbN4wVfJh2AdrgwdUcONkTCGgcMSW0jp1/zw=; b=wZcN12GnDVuunXZX0KBSwJEURmU0JU6IZrTZZvrqZUDtzTDAPW0KXaXnjCDkmib6e9 QPEiUhSEtd0ijVkrxXKis0PtVadOjIXGUkB5ymreu6Y0T2yPIv+V7lCSKrBBzeXNH2yz KfB5v0tPF19rX/malJg7QkDWTxhi3pEFWZA8U4L0dISB9QiFr2UMWUWgxa97ShMN4ikF GkGvRd96D810jVJw3VjEeda1SlM7qFmZ/M4YZqnmH+JEqyV/ks/HRFpreFV/SJUevzKA D6YzWXBxda/ln4hq5UZTSyrDkXv4x69+3bal7Q3XkjkFw8FiruaexmVHmvsGC3NLomh+ 5Q8A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a23si2227598pff.83.2018.02.23.11.07.51; Fri, 23 Feb 2018 11:08:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965437AbeBWS5f (ORCPT + 99 others); Fri, 23 Feb 2018 13:57:35 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50228 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965419AbeBWS5c (ORCPT ); Fri, 23 Feb 2018 13:57:32 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 58CD9EE2; Fri, 23 Feb 2018 18:57:31 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+5cb189720978275e4c75@syzkaller.appspotmail.com, Cong Wang , Florian Westphal , Eric Dumazet , Pablo Neira Ayuso Subject: [PATCH 4.15 18/45] netfilter: xt_RATEEST: acquire xt_rateest_mutex for hash insert Date: Fri, 23 Feb 2018 19:28:57 +0100 Message-Id: <20180223170718.257734414@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170715.197760019@linuxfoundation.org> References: <20180223170715.197760019@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cong Wang commit 7dc68e98757a8eccf8ca7a53a29b896f1eef1f76 upstream. rateest_hash is supposed to be protected by xt_rateest_mutex, and, as suggested by Eric, lookup and insert should be atomic, so we should acquire the xt_rateest_mutex once for both. So introduce a non-locking helper for internal use and keep the locking one for external. Reported-by: Fixes: 5859034d7eb8 ("[NETFILTER]: x_tables: add RATEEST target") Signed-off-by: Cong Wang Reviewed-by: Florian Westphal Reviewed-by: Eric Dumazet Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/xt_RATEEST.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) --- a/net/netfilter/xt_RATEEST.c +++ b/net/netfilter/xt_RATEEST.c @@ -39,23 +39,31 @@ static void xt_rateest_hash_insert(struc hlist_add_head(&est->list, &rateest_hash[h]); } -struct xt_rateest *xt_rateest_lookup(const char *name) +static struct xt_rateest *__xt_rateest_lookup(const char *name) { struct xt_rateest *est; unsigned int h; h = xt_rateest_hash(name); - mutex_lock(&xt_rateest_mutex); hlist_for_each_entry(est, &rateest_hash[h], list) { if (strcmp(est->name, name) == 0) { est->refcnt++; - mutex_unlock(&xt_rateest_mutex); return est; } } - mutex_unlock(&xt_rateest_mutex); + return NULL; } + +struct xt_rateest *xt_rateest_lookup(const char *name) +{ + struct xt_rateest *est; + + mutex_lock(&xt_rateest_mutex); + est = __xt_rateest_lookup(name); + mutex_unlock(&xt_rateest_mutex); + return est; +} EXPORT_SYMBOL_GPL(xt_rateest_lookup); void xt_rateest_put(struct xt_rateest *est) @@ -100,8 +108,10 @@ static int xt_rateest_tg_checkentry(cons net_get_random_once(&jhash_rnd, sizeof(jhash_rnd)); - est = xt_rateest_lookup(info->name); + mutex_lock(&xt_rateest_mutex); + est = __xt_rateest_lookup(info->name); if (est) { + mutex_unlock(&xt_rateest_mutex); /* * If estimator parameters are specified, they must match the * existing estimator. @@ -139,11 +149,13 @@ static int xt_rateest_tg_checkentry(cons info->est = est; xt_rateest_hash_insert(est); + mutex_unlock(&xt_rateest_mutex); return 0; err2: kfree(est); err1: + mutex_unlock(&xt_rateest_mutex); return ret; }