From patchwork Fri Apr 25 12:30:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Whitcroft X-Patchwork-Id: 342806 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id A863114016A; Fri, 25 Apr 2014 22:31:06 +1000 (EST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1WdfHR-00043U-Pu; Fri, 25 Apr 2014 12:31:01 +0000 Received: from mail-qc0-f173.google.com ([209.85.216.173]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1WdfHJ-0003z4-BV for kernel-team@lists.ubuntu.com; Fri, 25 Apr 2014 12:30:53 +0000 Received: by mail-qc0-f173.google.com with SMTP id r5so3929105qcx.32 for ; Fri, 25 Apr 2014 05:30:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zy7yKsy4GX2qMeYrprds8qpPbehvysT/ua9kOGE+E4c=; b=XAf4VxFUdnjDOtRSEyhDxNjNngazlShnFFfJENkf8oJ83reel85PsK+WvzpP+q9l3s HKk9Fz5m4p+JfMRhqQjld8QF4TWPzqucp5Bi3J+wap4qPtxEiCCAa/MistOtj3AFQjiT kDS0xpE3agCyJCFWpaADB4oVEZ+WXSn7InMKfDelhoZu06ysGE194TIQFdFU+vE9OakN H7zt4Tp+fHwuOGMRG9RVUkL1gCNmW7ITdodxxln3Z6Ur3majlIwhjHfZgvRgPobAZkXK NeZx69k/1vi6OcWBVHIKyc9UtSdKWaDumXb0LIUA5oSbwyr2O7PgEz4Zqha0Vrk3y9Ib zIcA== X-Gm-Message-State: ALoCoQlKHMhsXJcd3qD0QndlOZcw4prRz20CHoh+nFTP9dEXaow1ON15Bg2RmFpnjo6JJ4otao2a X-Received: by 10.140.87.207 with SMTP id r73mr2293364qgd.110.1398429052790; Fri, 25 Apr 2014 05:30:52 -0700 (PDT) Received: from localhost ([2001:470:6973:2:221:70ff:fe81:b177]) by mx.google.com with ESMTPSA id n3sm14021577qaf.36.2014.04.25.05.30.51 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 25 Apr 2014 05:30:52 -0700 (PDT) From: Andy Whitcroft To: kernel-team@lists.ubuntu.com Subject: [saucy/trusty 1/1] net: ipv4: current group_info should be put after using. Date: Fri, 25 Apr 2014 13:30:40 +0100 Message-Id: <1398429040-12559-5-git-send-email-apw@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1398429040-12559-1-git-send-email-apw@canonical.com> References: <1398429040-12559-1-git-send-email-apw@canonical.com> Cc: Andy Whitcroft X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com From: "Wang, Xiaoming" Plug a group_info refcount leak in ping_init. group_info is only needed during initialization and the code failed to release the reference on exit. While here move grabbing the reference to a place where it is actually needed. Signed-off-by: Chuansheng Liu Signed-off-by: Zhang Dongxing Signed-off-by: xiaoming wang Signed-off-by: David S. Miller (cherry picked from commit b04c46190219a4f845e46a459e3102137b7f6cac) CVE-2014-2851 Signed-off-by: Andy Whitcroft --- net/ipv4/ping.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c index d8878747..0432e77 100644 --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c @@ -248,26 +248,33 @@ int ping_init_sock(struct sock *sk) { struct net *net = sock_net(sk); kgid_t group = current_egid(); - struct group_info *group_info = get_current_groups(); - int i, j, count = group_info->ngroups; + struct group_info *group_info; + int i, j, count; kgid_t low, high; + int ret = 0; inet_get_ping_group_range_net(net, &low, &high); if (gid_lte(low, group) && gid_lte(group, high)) return 0; + group_info = get_current_groups(); + count = group_info->ngroups; for (i = 0; i < group_info->nblocks; i++) { int cp_count = min_t(int, NGROUPS_PER_BLOCK, count); for (j = 0; j < cp_count; j++) { kgid_t gid = group_info->blocks[i][j]; if (gid_lte(low, gid) && gid_lte(gid, high)) - return 0; + goto out_release_group; } count -= cp_count; } - return -EACCES; + ret = -EACCES; + +out_release_group: + put_group_info(group_info); + return ret; } EXPORT_SYMBOL_GPL(ping_init_sock);