From patchwork Mon Sep 18 18:33:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9957367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B7EF060385 for ; Mon, 18 Sep 2017 18:35:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACA1F28D33 for ; Mon, 18 Sep 2017 18:35:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A153128D36; Mon, 18 Sep 2017 18:35:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 515DA28D33 for ; Mon, 18 Sep 2017 18:35:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754328AbdIRSfb (ORCPT ); Mon, 18 Sep 2017 14:35:31 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33446 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753006AbdIRSf3 (ORCPT ); Mon, 18 Sep 2017 14:35:29 -0400 Received: by mail-pf0-f194.google.com with SMTP id h4so516184pfk.0; Mon, 18 Sep 2017 11:35:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=cv0QJiN4su7z44SAqYEX4OwZ9ePF4Ev1UyKLxo2isYE=; b=FXYQ8SvYNLOTwiV4ltXt2vbQoBQzeptXyFeVSlMQyshyKxkvZubpWDTdmQZSjIouBo SqQVV4Wx1wdMHrJsM/hiswiZiTaNgMZPPV0g3P9ZxLHEuP/yK4xH8JGdAJbRqKaqRJIt 6vvuUElCDXYj8QlUr0y8fvZC+mfzT5IyVsXPSUAreCJbVLZGO/Chhvp6lmkqYo82bIlr +3YMTDU9rRlrueo0erJ2ob+QvDKxujuRwz+lB1XI2zF0DXEHHlV4xDwwIfe6GuAMqekL h1ltX7Fga10OxagyfTBadvtGAPty7UkXH6OdOVZ8tuv1InX4q+Pendu8EelvolcVvNjk cr6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=cv0QJiN4su7z44SAqYEX4OwZ9ePF4Ev1UyKLxo2isYE=; b=fJV+LH9GWiriKaH9sRl62Pt1iMUC/JqAUtjzmUG+8I6T30KQCC9HPhqU8zs4M7sPtG dsPKIkT0GOTIzwhs3q4c+B3XfOGXifpNAbL+Lp56U5ln/Kzm3inFYR4ibbT7S7oIqU19 iMf4XD+OWF6qnN59W3JTTBgu2WiDn1BUI27td9eedchRZ6MOuppELnfZPOKGSHbALyPo 9eKX44Abyhe0QhYYNO5GQQhE2jvrsBNga31ny8iea8GDjbHtrPmVCgHUBtuaJShIzMmi T3uQofxbBHczv4ZqcpNqcITXXZKuV4dXgSBSTld14yowX2+LCAjTRnR3xZzBsm5rpsXo KhMw== X-Gm-Message-State: AHPjjUheLV7Xo7QvdV7ucvT/kGPV+/E2FkYOwHG9DG50YcMBCge2twLo QiLdX8LmTrfdsd2rJqc= X-Google-Smtp-Source: ADKCNb6kvcDWeVgDPmMGHL3esyQ0kpREJWy76DQVKs4948M07Y5pLHK8Lfsh5XcslvSSKfqETrngKg== X-Received: by 10.99.7.205 with SMTP id 196mr32756579pgh.356.1505759728737; Mon, 18 Sep 2017 11:35:28 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.174.81]) by smtp.gmail.com with ESMTPSA id l12sm65553pgp.74.2017.09.18.11.35.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Sep 2017 11:35:27 -0700 (PDT) From: Eric Biggers To: keyrings@vger.kernel.org Cc: David Howells , Michael Halcrow , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH] KEYS: fix cred refcount leak in request_key_auth_new() Date: Mon, 18 Sep 2017 11:33:31 -0700 Message-Id: <20170918183331.113261-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.14.1.690.gbb1197296e-goog Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers In request_key_auth_new(), if alloc_key() or key_instantiate_and_link() were to fail, we would leak a reference to the 'struct cred'. Currently this can only happen if alloc_key() fails to to allocate memory. But it still should be fixed, as it is a more severe bug waiting to happen. Fixes: d84f4f992cbd ("CRED: Inaugurate COW credentials") Signed-off-by: Eric Biggers --- security/keys/request_key_auth.c | 1 + 1 file changed, 1 insertion(+) diff --git a/security/keys/request_key_auth.c b/security/keys/request_key_auth.c index afe9d22ab361..f2f29f13ecff 100644 --- a/security/keys/request_key_auth.c +++ b/security/keys/request_key_auth.c @@ -227,6 +227,7 @@ struct key *request_key_auth_new(struct key *target, const void *callout_info, key_revoke(authkey); key_put(authkey); error_alloc: + put_cred(rka->cred); key_put(rka->target_key); key_put(rka->dest_keyring); kfree(rka->callout_info);