From patchwork Tue Jun 23 19:54:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 223216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97A10C433DF for ; Tue, 23 Jun 2020 21:17:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A8CB2078E for ; Tue, 23 Jun 2020 21:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592947073; bh=9YmC30CBs5fIMIMnajxNVucl7OFNhF85IfK4dlpZ0J0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=pZIYt33lv+LkmgbGuv06m6ux7k4f5gkyYRIE+oYLJADfN9DKunFW0STS5X83/fL6R ZlvfRYz9+Io3WO+LTXtMgFQVgwakdTF6A6y3/gTfnaSdfew6WFvj0wNj3thg6QK7DN WlPNHS7hoklmIiE+5vEqzR/w0wc/N+gnlajDyjxo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390129AbgFWU0a (ORCPT ); Tue, 23 Jun 2020 16:26:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:45684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390654AbgFWU03 (ORCPT ); Tue, 23 Jun 2020 16:26:29 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2A96B20702; Tue, 23 Jun 2020 20:26:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592943989; bh=9YmC30CBs5fIMIMnajxNVucl7OFNhF85IfK4dlpZ0J0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kw2eXpN5TojHhmtEqqSm/tGd0P1u7A3Lj+f2eyRaeUVKybUmLHQv3hdwn5K7SJtR/ u1Tu5MgYkAARBwMt5QTYhilepm0zMn082BHcw96UgvNo13SeWumq9qhCV468aUH8rM hEEh8ZOYDnNckqrsKIqVFdkB2cbNZdbJKKYfKepU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiyu Yang , Xin Tan , Sasha Levin Subject: [PATCH 5.4 098/314] staging: gasket: Fix mapping refcnt leak when register/store fails Date: Tue, 23 Jun 2020 21:54:53 +0200 Message-Id: <20200623195343.533198356@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195338.770401005@linuxfoundation.org> References: <20200623195338.770401005@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Xiyu Yang [ Upstream commit e3436ce60cf5f5eaedda2b8c622f69feb97595e2 ] gasket_sysfs_register_store() invokes get_mapping(), which returns a reference of the specified gasket_sysfs_mapping object to "mapping" with increased refcnt. When gasket_sysfs_register_store() returns, local variable "mapping" becomes invalid, so the refcount should be decreased to keep refcount balanced. The reference counting issue happens in one exception handling path of gasket_sysfs_register_store(). When gasket_dev is NULL, the function forgets to decrease the refcnt increased by get_mapping(), causing a refcnt leak. Fix this issue by calling put_mapping() when gasket_dev is NULL. Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan Link: https://lore.kernel.org/r/1587618941-13718-1-git-send-email-xiyuyang19@fudan.edu.cn Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/gasket/gasket_sysfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c index ad852ea1d4a92..af26bc9f184a5 100644 --- a/drivers/staging/gasket/gasket_sysfs.c +++ b/drivers/staging/gasket/gasket_sysfs.c @@ -373,6 +373,7 @@ ssize_t gasket_sysfs_register_store(struct device *device, gasket_dev = mapping->gasket_dev; if (!gasket_dev) { dev_err(device, "Device driver may have been removed\n"); + put_mapping(mapping); return 0; }