Received: by 10.223.185.116 with SMTP id b49csp1107076wrg; Fri, 23 Feb 2018 12:03:46 -0800 (PST) X-Google-Smtp-Source: AH8x226Qs7EuyVD3gRQhny8LPMqQ7K+cwrXEEyTAO1RlHWg5g/105KyWo7nzh4P4iJlz1gJd8mTi X-Received: by 2002:a17:902:bc41:: with SMTP id t1-v6mr2781862plz.436.1519416225972; Fri, 23 Feb 2018 12:03:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519416225; cv=none; d=google.com; s=arc-20160816; b=c3weHQf+0UuTg9RxAyq9BgEprQwrH4ZN+p/Sdx/jRv2bj5gYVOo2MSrYUFHLN3IyJ1 XU6pdQ5ImPU0GfxAoutFHpaNF0eanYmdQC8CfU13cmpGve0Wv4WSZh/IWbpxtIs1iCkZ vBkJID62YHBNyul3h9Ogr1O5y9GeeHmM9fkWDsOPyen40S5C/Kp3s/W0feTlDhAwtsRR begWtq6wtKi7JYtV12Th0cCWY//dVgnyR/P6WagHqswEQhw/LFWli9BgqrUto6JyxwmN HSleZnoWTiT5qiNOSC4wEP16BfeuPwO8trOSIEHhBbDBw4RfQucgNnNl2mZfTXvyfFWu lKZA== 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=Ys6AyGnBmuO1KvbZmY42pcJwRXWNaSMiCFc1COyeaY8=; b=xSX6J71F8LvHCWW8Y/t3IjXae1SjyenPGIaGn8CWF3O+SzY5qo4YhUv3WBqha6uiyn Bd6AoU72CA7+wB8KRLky7GPPeY8J1cRFTUhMuyvNZFgFjO7qqp9CSLBnu3uyhwKl9iAd QEqE6Q2/7urShjvmWkjWF1J/OW/RIPCjr/2Y02uH90HLXFh6SgiFuOpoaefvh6XQjRIV DTzZ8sUbfuuLiqlisarSnTRAmiZRDYYiQObQTYN8XHCcHoErFHn6xvD0GQbh9YUKM2Z/ GNsyHthSCCdpo6Z/Jld6Hp3aHqH0P4aCnJ/KZs+Xw7SEt4A5qElHIy4l4Oss2Or2GgG2 7wEg== 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 j12si1882994pgn.115.2018.02.23.12.03.31; Fri, 23 Feb 2018 12:03:45 -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 S933260AbeBWSnS (ORCPT + 99 others); Fri, 23 Feb 2018 13:43:18 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42116 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933233AbeBWSnM (ORCPT ); Fri, 23 Feb 2018 13:43:12 -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 1716C10BE; Fri, 23 Feb 2018 18:43:11 +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.9 027/145] netfilter: xt_RATEEST: acquire xt_rateest_mutex for hash insert Date: Fri, 23 Feb 2018 19:25:33 +0100 Message-Id: <20180223170728.367414272@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170724.669759283@linuxfoundation.org> References: <20180223170724.669759283@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.9-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; }