From mboxrd@z Thu Jan 1 00:00:00 1970 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=-11.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 0D476C55186 for ; Thu, 23 Apr 2020 11:45:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D287320787 for ; Thu, 23 Apr 2020 11:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587642335; bh=pZa2nkfiz+IeJ4GJXA5/5UFzWbJg3mh7gXzhLHL+GPs=; h=Subject:To:From:Date:List-ID:From; b=q5Mpl62LeaikNrvJUNHF20TszL6j0dDCUbPJL+XfPWuKu9m58zF8PNBe119fKBaYu eTRzCR6j4SHfcYz71G0lssSnYc/iwHl+3BdPmnGcvbBqVakwFYiVT4ZphIOciv4kei Uyr2MlmZnV5dYjrJ8peu9ldS7e8cVJQScYl1YuoI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727911AbgDWLpf (ORCPT ); Thu, 23 Apr 2020 07:45:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:54518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727088AbgDWLpf (ORCPT ); Thu, 23 Apr 2020 07:45:35 -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 5B29C2077D; Thu, 23 Apr 2020 11:45:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587642334; bh=pZa2nkfiz+IeJ4GJXA5/5UFzWbJg3mh7gXzhLHL+GPs=; h=Subject:To:From:Date:From; b=SuHNw/dhj423ReowN3PsfcFMAfL4/94FbYkzu+NVi34dxXdqQSGhgIojtl7pQuieO j/YjJmRBxOfM0j8OQE6LwJW+jjKBuanMUTA3y3maBb3Qe8mWzEgVH5yW7Q4T4pMt4i ZC/FY9W3qVSBxrJ70qUm3hL/taTk1Cota+ejSFNQ= Subject: patch "staging: comedi: Fix comedi_device refcnt leak in comedi_open" added to staging-linus To: xiyuyang19@fudan.edu.cn, abbotti@mev.co.uk, gregkh@linuxfoundation.org, stable@vger.kernel.org, tanxin.ctf@gmail.com From: Date: Thu, 23 Apr 2020 13:45:32 +0200 Message-ID: <1587642332209228@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org This is a note to let you know that I've just added the patch titled staging: comedi: Fix comedi_device refcnt leak in comedi_open to my staging git tree which can be found at git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git in the staging-linus branch. The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.) The patch will hopefully also be merged in Linus's tree for the next -rc kernel release. If you have any questions about this process, please let me know. >From 332e0e17ad49e084b7db670ef43b5eb59abd9e34 Mon Sep 17 00:00:00 2001 From: Xiyu Yang Date: Mon, 20 Apr 2020 13:44:16 +0800 Subject: staging: comedi: Fix comedi_device refcnt leak in comedi_open comedi_open() invokes comedi_dev_get_from_minor(), which returns a reference of the COMEDI device to "dev" with increased refcount. When comedi_open() returns, "dev" becomes invalid, so the refcount should be decreased to keep refcount balanced. The reference counting issue happens in one exception handling path of comedi_open(). When "cfp" allocation is failed, the refcnt increased by comedi_dev_get_from_minor() is not decreased, causing a refcnt leak. Fix this issue by calling comedi_dev_put() on this error path when "cfp" allocation is failed. Fixes: 20f083c07565 ("staging: comedi: prepare support for per-file read and write subdevices") Signed-off-by: Xiyu Yang Cc: stable Signed-off-by: Xin Tan Signed-off-by: Ian Abbott Link: https://lore.kernel.org/r/1587361459-83622-1-git-send-email-xiyuyang19@fudan.edu.cn Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/comedi_fops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 08d1bbbebf2d..e84b4fb493d6 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -2725,8 +2725,10 @@ static int comedi_open(struct inode *inode, struct file *file) } cfp = kzalloc(sizeof(*cfp), GFP_KERNEL); - if (!cfp) + if (!cfp) { + comedi_dev_put(dev); return -ENOMEM; + } cfp->dev = dev; -- 2.26.2