From patchwork Thu May 21 18:31:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Menage X-Patchwork-Id: 27494 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 8489AB6F35 for ; Fri, 22 May 2009 04:34:33 +1000 (EST) Received: by ozlabs.org (Postfix) id 57243DE1CE; Fri, 22 May 2009 04:34:33 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id D8BC9DE14E for ; Fri, 22 May 2009 04:34:32 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753735AbZEUSeY (ORCPT ); Thu, 21 May 2009 14:34:24 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752954AbZEUSeX (ORCPT ); Thu, 21 May 2009 14:34:23 -0400 Received: from smtp-out.google.com ([216.239.33.17]:14965 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752720AbZEUSeW (ORCPT ); Thu, 21 May 2009 14:34:22 -0400 Received: from spaceape10.eur.corp.google.com (spaceape10.eur.corp.google.com [172.28.16.144]) by smtp-out.google.com with ESMTP id n4LIVUxf029132; Thu, 21 May 2009 19:31:31 +0100 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1242930692; bh=ElF0ryawH4aGveXMiqnAQPRaXfw=; h=DomainKey-Signature:From:Subject:To:Cc:Date:Message-ID:User-Agent: MIME-Version:Content-Type:Content-Transfer-Encoding: X-System-Of-Record; b=wDh2nXfpNDcNdlD2gotgoUuDFfBfz8BmDkk4/qdXd70s NCRp51MmqESkKmXiTSC03lpzYi3xkhWIeLMRkWQtYA== DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=from:subject:to:cc:date:message-id:user-agent: mime-version:content-type:content-transfer-encoding:x-system-of-record; b=GoPvrqkrpk9E2wZp8uR7knRDEY+Z8GhP4JNUaMmZ4TEVNBMxx/+nTQntoAhd9RWmS 9sLFo1FdBSG3aFUryycEQ== Received: from localhost (menage.mtv.corp.google.com [172.22.66.80]) by spaceape10.eur.corp.google.com with ESMTP id n4LIVQBe017536; Thu, 21 May 2009 11:31:27 -0700 Received: from menage.mtv.corp.google.com (localhost.localdomain [127.0.0.1]) by localhost (Postfix) with ESMTP id B04353D6A4E; Thu, 21 May 2009 11:31:26 -0700 (PDT) From: Paul Menage Subject: [PATCH] cls_cgroup: read classid atomically in classifier To: lizf@cn.fujitsu.com, akpm@linux-foundation.org, davem@davemloft.net, tgraf@suug.ch Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Date: Thu, 21 May 2009 11:31:26 -0700 Message-ID: <20090521183100.12678.28835.stgit@menage.mtv.corp.google.com> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-System-Of-Record: true Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org cls_cgroup: read classid atomically in classifier Avoid reading the unsynchronized value cs->classid multiple times, since it could change concurrently from non-zero to zero; this would result in the classifier returning a positive result with a bogus (zero) classid. Signed-off-by: Paul Menage Reviewed-by: Li Zefan --- Resending to cc netdev@vger.kernel.org as requested by DaveM net/sched/cls_cgroup.c | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c index 1ab4542..4ece6e0 100644 --- a/net/sched/cls_cgroup.c +++ b/net/sched/cls_cgroup.c @@ -98,8 +98,7 @@ static int cls_cgroup_classify(struct sk_buff *skb, struct tcf_proto *tp, struct tcf_result *res) { struct cls_cgroup_head *head = tp->root; - struct cgroup_cls_state *cs; - int ret = 0; + u32 classid; /* * Due to the nature of the classifier it is required to ignore all @@ -115,17 +114,18 @@ static int cls_cgroup_classify(struct sk_buff *skb, struct tcf_proto *tp, return -1; rcu_read_lock(); - cs = task_cls_state(current); - if (cs->classid && tcf_em_tree_match(skb, &head->ematches, NULL)) { - res->classid = cs->classid; - res->class = 0; - ret = tcf_exts_exec(skb, &head->exts, res); - } else - ret = -1; - + classid = task_cls_state(current)->classid; rcu_read_unlock(); - return ret; + if (!classid) + return -1; + + if (!tcf_em_tree_match(skb, &head->ematches, NULL)) + return -1; + + res->classid = classid; + res->class = 0; + return tcf_exts_exec(skb, &head->exts, res); } static unsigned long cls_cgroup_get(struct tcf_proto *tp, u32 handle)