Received: by 10.223.185.116 with SMTP id b49csp1074009wrg; Fri, 23 Feb 2018 11:26:48 -0800 (PST) X-Google-Smtp-Source: AH8x225BDJq9p2j83t++x3f3+PlNTE/B5tgAntTATkALmmq3wG28j3+UmHyftTd5GQdHUekzSdBd X-Received: by 2002:a17:902:4e25:: with SMTP id f34-v6mr2585446ple.68.1519414008078; Fri, 23 Feb 2018 11:26:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519414008; cv=none; d=google.com; s=arc-20160816; b=SSac2KwXfzNwsQQwTofapVWqDDZ/h0disu+4ITtQkbgzZALdiBZLHg7DcZBX6nvrnP L6GYvqKCC9HZNSuVSSzcOKtJXp118LdDyj9z5dAEXYYP/JIoB4bJdQwf9H9kuG2KDEHc 6Y8B7D/16hXqMwwLtBBXWyWHt4rr5Pm+JHxl9WGycyAKJmc7O37WFiClyhXoW3tTYkDn eBU+4m3EBH1DbNNs1LA8HI/k4AsMN8eE0GVQffAPYLZKlo8/VJVkPQ4Wk3bn6LCFl/Tr NtDUHyrs8vJkquaATngVj0p1/Wa8wKtb6JA5XX+Shc+01tAMaDEHIWrpEOSpGqTRoPAQ MrAQ== 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=RH0lYvq9OBLMDwtZDesALYffQLj7J0ZKwLPtqxos7NY=; b=NxPr8ePfK2J9oU6jhNNQM/dy6y2cYpvNiNKDzCdcH73/3lV/RcLH6O9gysDqmZuUnT 0PvJPhp9N8hZD8uK46wEbP4CsobSTmWm4iGmNRfK+O24YoXzgMCXrlwNxpCw2RFAN2/O OU/1j+qfcMWlfCi3koMy4C/bakio/1YDuog05nkzXq2iHqPNx0xAT5NOw4AVIxgLU3kp 75lV6fcheETu0PPXIGktBk7jo/7KnXbwfgqliMwXHt6doo/ELzzFvWrX2LhI0fxXmPFy uoCK9FlCgDeK/zGo5qDchJ7STMhzN5eF/DUBqM7djpZ+dtPcFAEEzDxqTHiC+BVvc0Ih KdTw== 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 c6si1862926pgn.681.2018.02.23.11.26.33; Fri, 23 Feb 2018 11:26:48 -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 S935211AbeBWSwq (ORCPT + 99 others); Fri, 23 Feb 2018 13:52:46 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:47070 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935166AbeBWSwn (ORCPT ); Fri, 23 Feb 2018 13:52:43 -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 BA778FCE; Fri, 23 Feb 2018 18:52:42 +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.14 040/159] netfilter: xt_RATEEST: acquire xt_rateest_mutex for hash insert Date: Fri, 23 Feb 2018 19:25:48 +0100 Message-Id: <20180223170748.289683050@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170743.086611315@linuxfoundation.org> References: <20180223170743.086611315@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.14-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; }