Received: by 10.223.185.116 with SMTP id b49csp1143834wrg; Fri, 23 Feb 2018 12:43:29 -0800 (PST) X-Google-Smtp-Source: AH8x224ZiG3LwAYnbB9EbfnWeFKWQqX/PPLAZ8ctKSPU78Cl/+KlPtz+l3vHFSPS7S8lsEGTJYvg X-Received: by 2002:a17:902:6ac7:: with SMTP id i7-v6mr2806741plt.434.1519418609190; Fri, 23 Feb 2018 12:43:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519418609; cv=none; d=google.com; s=arc-20160816; b=EWOM4IGJiWI3VLnn3xLnO/8gOxPWFOiP5vXtNkM2hGVg+uzafhoBqle4l/DmtFy9vH lN8ylWgKE2KyzFwHDD/3QgX+g7XZbS+eaq9anxv2dPwo8clRoI1MvHFL+81/RMPghM8q ngaYVDvNB8pIl9Of8HOwJKbbeomWjcA7Hk5OnejFZBOzaaplgYnL0wyBpj/BM+Xv+foM 2s2LkVHM87HqMYsegIzMtJSleXeDZ0GG+1kv6UehSUeHZYlF7sU7z77jnbmMoU57EzV6 nC9+PxuU7JyR4Sf6cHylPidMuVyHDbjneoLa9fl8gy9Ro2MXUhUqUbSvZiCw4y1BzvhS OMyg== 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=J9qgXukxcpAIcB/AyfAt+GnWaCEGNQT3zusfMGNtUEE=; b=NlodZT3pebpinQzO88omUwMSwtx7F6swyIwAu6amvwZuFxzdACy9XLUdmfzvzSiJe5 RiB9QpI1OmNdn2Gk//ipVKFyEQEASHxmassM1N6hTUaEWX61ABXZikaDYykk2xsiHolM xHNYqRheMOkJLIuV5/JNjHt41Y0lZ7vx/USS829Z2j6NWOnI3AThoDoNsEXaOvanYSsh yjLU+9R0R27WKbDKXS8+8grJb489Wv/HTk1+1SLAjZPDUVlH5ywM9GISNPKaQf+Cw2Kx 3QuXnFVrrzebUCpeAVlDJojvsS/enx/BpPdx8Y3qgsQUVp1BOBxtQfgUZDDqMNiYG1jM Db2Q== 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 m27si2337755pfg.64.2018.02.23.12.43.14; Fri, 23 Feb 2018 12:43:29 -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 S1753202AbeBWSdY (ORCPT + 99 others); Fri, 23 Feb 2018 13:33:24 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36512 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753102AbeBWSdU (ORCPT ); Fri, 23 Feb 2018 13:33:20 -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 D8F4F1070; Fri, 23 Feb 2018 18:33:19 +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.4 019/193] netfilter: xt_RATEEST: acquire xt_rateest_mutex for hash insert Date: Fri, 23 Feb 2018 19:24:12 +0100 Message-Id: <20180223170329.070324493@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170325.997716448@linuxfoundation.org> References: <20180223170325.997716448@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.4-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 @@ -40,23 +40,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) @@ -104,8 +112,10 @@ static int xt_rateest_tg_checkentry(cons rnd_inited = true; } - 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. @@ -143,11 +153,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; }