Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp420879ybt; Wed, 24 Jun 2020 02:35:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1XpYPeHl9JjXiHDqrCRLsV9+cVvzzYCgu8W34oig9u43v/mgOXlLAZ2K+E8NQRXoyxty0 X-Received: by 2002:a50:d0cc:: with SMTP id g12mr5017795edf.57.1592991347773; Wed, 24 Jun 2020 02:35:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592991347; cv=none; d=google.com; s=arc-20160816; b=Ksovz3q9jGRAjZ8EHExO18s99f3TCvZwo8g19USz1OiWSMe4KZIF0IzerHkvbTpjfs haC13Eg7yLwAMnC2y6UBX0ZwMIhwpm4vORxaIpDOVD334p+xr2B/5CrCYH0F2n/EnGSd x2bAFF39zhApYm0AJZ7rI0hBu5p9koRbUe1Dlgyk1RwVU/zqCklYxB9N4lUFBoU6vq5H ZTdHVmRz42qsGahG2Lp/wkBYpoBCIfotTuqpySUzKYCjzCfn9YuIvjsfSi1on5+ueixR H42UkDfp58R3U693S97mkFEJmQQ66+Xi3gOILU9/U4DscNyzO1eytIT/VzOsKetC2m4D INXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=MaGFzZVdvFZYNljmyR4BUoJKwMZp6T7RtWcWGxgDmAM=; b=Ax5P9Ov2FgFlFlB2/TdMfruqyx6AdeKs3yMhpS56pCum5Fkg9aO6DMoS9DKCXSbxe8 xG5VoQvh2NW2B/Qh+FMdph2qeV08uO2nlGroNzmdnoo/1z/fNwaHlkQA72+pezXluZAl +0Eo1o5iRlRabkABxrE+42v9sWnkI0FXILFmVmUDwB4IEZGyZZdBhi27u5Tp+BXbjVMd q/R8qRRxJ57RRhhr8zVgYZDWGA4PwcBGGwYL5XKIW+o5zsIQk2wdvL7tj0BQ344/9NWB /vKhbzPFgKiR+hmB3GE+EegPnYTkkyWkPwKg9RTrqssqFzPLbWjAl26jtNHOt5jUSRf1 QkoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xuve8tMy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q23si846289edg.348.2020.06.24.02.35.23; Wed, 24 Jun 2020 02:35:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xuve8tMy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389285AbgFXJeJ (ORCPT + 99 others); Wed, 24 Jun 2020 05:34:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:40870 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387495AbgFXJeJ (ORCPT ); Wed, 24 Jun 2020 05:34:09 -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 EAF1220767; Wed, 24 Jun 2020 09:34:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592991248; bh=sICbUBxqvnNymzIHTAoebMoDGJFpflFpDIcZ1Z6LF88=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=xuve8tMyf3HRgy/Eo1NRgKSXn6+cAf7mU467oGgsAVQxcZsJNvqiJHfPVwVI2xUY8 hiAfozChkvoklpLt75moy7IyTOm7LbDKR89jESY1Ihn57+LROZJRGcC8zukJFAKVyV iEPG2ik34c0NwttLdXBfltgAnADHjss+rVU8AVAo= Date: Wed, 24 Jun 2020 11:34:07 +0200 From: Greg Kroah-Hartman To: Xiyu Yang Cc: Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, yuanxzhang@fudan.edu.cn, kjlu@umn.edu, Xin Tan Subject: Re: [PATCH] tty: serial_core: Fix uart_state refcnt leak when the port startup Message-ID: <20200624093407.GB1751086@kroah.com> References: <1592052738-95202-1-git-send-email-xiyuyang19@fudan.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1592052738-95202-1-git-send-email-xiyuyang19@fudan.edu.cn> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 13, 2020 at 08:52:18PM +0800, Xiyu Yang wrote: > uart_port_startup() invokes uart_port_lock(), which returns a reference > of the uart_port object if increases the refcount of the uart_state > object successfully or returns NULL if fails. > > However, uart_port_startup() don't take the return value of > uart_port_lock() as the new uart_port object to "uport" and use the old > "uport" instead to balance refcount in uart_port_unlock(), which may > cause a redundant decrement of refcount occurred when the new "uport" > equals to NULL and then cause a potential memory leak. > > Fix this issue by update the "uport" object to the return value of > uart_port_lock() when invoking uart_port_lock(). > > Signed-off-by: Xiyu Yang > Signed-off-by: Xin Tan > --- > drivers/tty/serial/serial_core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c > index 57840cf90388..968fd619aec0 100644 > --- a/drivers/tty/serial/serial_core.c > +++ b/drivers/tty/serial/serial_core.c > @@ -205,7 +205,7 @@ static int uart_port_startup(struct tty_struct *tty, struct uart_state *state, > if (!page) > return -ENOMEM; > > - uart_port_lock(state, flags); > + uport = uart_port_lock(state, flags); How is this a different pointer than you originally had? And if it is a different pointer, shouldn't you be calling this function and using the pointer much earlier in the function instead of just here? Can you trigger a problem that this patch solves? If so, how? thanks, greg k-h