Received: by 10.213.65.68 with SMTP id h4csp2119561imn; Sun, 8 Apr 2018 20:11:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+ZOwt5LTgw4xGibbax9dTiaLLw6nldmyDtIAaUxWMCd7pEKvcVqkx+c9q+XOx9Y6PAfwOf X-Received: by 10.99.113.83 with SMTP id b19mr23835060pgn.167.1523243392973; Sun, 08 Apr 2018 20:09:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243392; cv=none; d=google.com; s=arc-20160816; b=XlfxXCm5QMrK+dHLJmqKawiWhlukhS2qM3Jyefx+CMMAt/JXlVyhwi619OZ1s2PNI2 7sy6BPDz1lnwnbfiojyZFwoHVlTd7Mk1kPdtkr+xz1/66K03L1RqHJwkirTLYDaJYEBu wVMDhHBQbF+LsH4FfUIlD+IiqbWu2ZZLKSsD21nXsZyHfYxPw3O/jQGNZTpVWd/CwTrS Sntrijl5eZoM1TRzdLRpZ1ZHvkL0JO0gQTVPNOKIyUBzTCul45Sm2tRkPnr9BGFx9NMY Cg3h78P+PHFg1i3BkTLNwE2jzMCuYsj5u7NqR1ZEqLwEHFIsDGVQMA9gisppaHOaZKwn gHnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=RrDNpDxJsS9sHK//6SdatuvWbZdIawAUdAd2FcduF4k=; b=PiWY1wBawpcBnGEBsSHE1EVhZy43EO+Yo/HDxDALmnkZP0zALMRkyeUpNwofqNMmoG D8iE/84ACooXYktaOj7IKAzpeGnwPJ1kvx+xGT1SfE5CYISx7ufcuH7cCwEWzn/zMjxx L4yqdySbik0yv5xAS1Y9RvyxJVfhyhSjN0QZx9mSxlZS392j15w6uhqOTZxLq52Aisny pQJ4zdpvD7pqAuDBg5+c057dQ8hGiCBC+fkHUuCZA5IBZxRnWRPA8G1R0xUNAkSSxemL bRqY2fEKE+Dd8UzMcQANOdDyuu63BE3ROab4TK6J/vcLRQ7FIJ8j3MGTa9juevMFistX mIcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=GNLpkmCx; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4-v6si13617335plb.205.2018.04.08.20.09.16; Sun, 08 Apr 2018 20:09:52 -0700 (PDT) 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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=GNLpkmCx; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932958AbeDICp2 (ORCPT + 99 others); Sun, 8 Apr 2018 22:45:28 -0400 Received: from mail-by2nam03on0126.outbound.protection.outlook.com ([104.47.42.126]:2432 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755431AbeDIA0r (ORCPT ); Sun, 8 Apr 2018 20:26:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=RrDNpDxJsS9sHK//6SdatuvWbZdIawAUdAd2FcduF4k=; b=GNLpkmCx9hLX3VtgUDKL98GB8REtVezXelgiovjwiTrmENYO0dLBwd+tDJgUvRoMNnE8dJWpW5NU3WjJvEtwwA4Kth+dWY6QLFx/ngcY+2GTAWG/obAm9bE9GRU+mBTdkdXQGESEqJ1QG6MJsTrzs+qPFqDm9UFmpf606HDPvvc= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0885.namprd21.prod.outlook.com (52.132.132.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:26:41 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:26:41 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Eric Biggers , David Howells , James Morris , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 019/293] KEYS: put keyring if install_session_keyring_to_cred() fails Thread-Topic: [PATCH AUTOSEL for 4.9 019/293] KEYS: put keyring if install_session_keyring_to_cred() fails Thread-Index: AQHTz5jtGnmuQfwfeEKEfBg5kJRIXA== Date: Mon, 9 Apr 2018 00:23:04 +0000 Message-ID: <20180409002239.163177-19-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0885;7:5BpAJ6Z076A6rYOFMrlu8ackJrsI1l0accGVbfkkINkStPlfiGziQW4DChwmQaB3qq1pt5DgmKlOaiXZKfAlOsO+MUobtRp4WHmR8/eQ9oYOV5RQvt6Jl/TwL4Jcl05IqgFIjlo8F+Fw0izoCcM/vx2Qg16eqz2e5JtgC9wd8/MdGX6mSrEl8L6YG3SGvGEqD0QexEfzkJ3CsEU21zX81MJS5QvtZkrR1TWJMxVRQqT0wv9BkLq6WIn5V31Va04x;20:HU8sXx22KbK0UIw+EoNK/HK3RUAndQvpNiZpB+D7XUWgxOnelCOCITAu5pnKpUC+ETVV5nQ0rDB1Uq3qhT4O72B0lfPoAPHUXzny1CuAjsKcfiaffUk50WvprabLX4Af8IPRNusXmeEoG7eENYWWktvEdGe8+KotwLtvjQUP22k= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: e15ddc76-bd9c-4377-e724-08d59db090e1 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0885; x-ms-traffictypediagnostic: DM5PR2101MB0885: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(192374486261705)(211936372134217)(153496737603132)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0885;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0885; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(366004)(346002)(376002)(396003)(39380400002)(189003)(199004)(2906002)(68736007)(22452003)(316002)(6512007)(5660300001)(6666003)(54906003)(110136005)(486006)(6486002)(102836004)(36756003)(14454004)(99286004)(86612001)(105586002)(72206003)(106356001)(2900100001)(1076002)(97736004)(10090500001)(3280700002)(5250100002)(6436002)(3660700001)(6116002)(3846002)(305945005)(86362001)(59450400001)(66066001)(10290500003)(186003)(81166006)(8936002)(478600001)(476003)(25786009)(81156014)(8676002)(4326008)(7736002)(2501003)(107886003)(6506007)(2616005)(26005)(76176011)(446003)(53936002)(11346002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0885;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: eQLFExeDux+pw1skXmmY5gaHra8OCL/5ibPOfEF0d+9QyYYBBFt5mQ7vebyXk3XQLX+q4CeAt3mNPkl3RUGGFYIstHN57wwJLat1uPPKR24CuxuN+UtHVgc+33YgigEKHCpw6Ch33uQnxLV9mmP+CUPQEibVgoNgXDGfzxXROLcnRvvqI63QRJTtYn67dI84KVi4Z2ZpzgjX6KLsHRVjLLeMoCHYlD/3lC8+oFoP/7ULF3qk/6mnzbMAcB3AY+01eDGc5Fike7bzRXIuBFklIUz6S0oFMttS1p4FYQriFcn9BCeiKu6eyTQFmhVdKB9Mt/tmncRUkrkyhw9oJ3MlKmfVenGDhDdosSCWl6dq1ew6wnNXxeLC4eW3QvwVTaJ6ByRgolR/+iJIJ8Zh0Fo8E/P7vKvdWPPZB4xDLIMamko= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: e15ddc76-bd9c-4377-e724-08d59db090e1 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:23:04.6435 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0885 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers [ Upstream commit d636bd9f12a66ea3775c9fabbf3f8e118253467a ] In join_session_keyring(), if install_session_keyring_to_cred() were to fail, we would leak the keyring reference, just like in the bug fixed by commit 23567fd052a9 ("KEYS: Fix keyring ref leak in join_session_keyring()"). Fortunately this cannot happen currently, but we really should be more careful. Do this by adding and using a new error label at which the keyring reference is dropped. Signed-off-by: Eric Biggers Signed-off-by: David Howells Signed-off-by: James Morris Signed-off-by: Sasha Levin --- security/keys/process_keys.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c index 2d35d71d7d9a..88c94e6c2158 100644 --- a/security/keys/process_keys.c +++ b/security/keys/process_keys.c @@ -810,15 +810,14 @@ long join_session_keyring(const char *name) ret =3D PTR_ERR(keyring); goto error2; } else if (keyring =3D=3D new->session_keyring) { - key_put(keyring); ret =3D 0; - goto error2; + goto error3; } =20 /* we've got a keyring - now to install it */ ret =3D install_session_keyring_to_cred(new, keyring); if (ret < 0) - goto error2; + goto error3; =20 commit_creds(new); mutex_unlock(&key_session_mutex); @@ -828,6 +827,8 @@ long join_session_keyring(const char *name) okay: return ret; =20 +error3: + key_put(keyring); error2: mutex_unlock(&key_session_mutex); error: --=20 2.15.1