Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp328139ybt; Sat, 13 Jun 2020 05:55:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwE9xnRJNRpyYAUXuVE7EVAWi7HP5Ir3LR9vg5G6CUsTHp96Exw1PZsmh5NhA37Y46zDT8g X-Received: by 2002:a05:6402:128f:: with SMTP id w15mr16383972edv.240.1592052948188; Sat, 13 Jun 2020 05:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592052948; cv=none; d=google.com; s=arc-20160816; b=nuRNK38tqOTjWGm5EttY38/XS2jf8bh6zNubJWLAkQNCGQDNJmvT3luxHxSXByCVS0 CR8m3RDnkvS8ejTrXrfoWyZ4d7EzywvgYrCZdW5TJI3jYgil9iYJMKlMB3XGRXdcolOy OxzDqSXsMlQufPZ6Scc2wGT76SHjG5uRhWaiR593TaSYVbxk0VZ09t0PsKdJWb9zo9hT +xQeGrwHw3GykeEPW0lpXeyg70I+5tkJKsknlZ+Yx4E7h/i2IYgO17aC/v/JEqIClDk1 ePKinxshxwrqcAdfM+owKE9EInLEkUjQ92ZlzC4ZHiZ0HAz7Vg4dDQzkomIc/o8lb+ye Pkxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=oeRbaKJ4ubcIH3C117R3MYxefSczLaaLiNN/4rd1qYA=; b=oHX0IWW3gUycr5o7JeKlsYNBt3c1yvPsr0X9K797ETikyg735mxZ8YCS48UsQrH58Z E+yr4YrzJ/iMZyCod+RCFixovIVpXIUQbQzLdr9HUBkr1k+pzVvObr9eHBcW7Knm3dMT fKjazoqgWD3O3mUbM9CESS1layh69PXBLDGefO1RW5Pk2q4QZnRIpDQBMr+SvfLvcaNR v85bpvWIk0ErzkCqnIbo3x3lifAaTkvzBWX2VWbZKDGnjn1gpIZHU0VtbWL1sO0DfKzW vBjtBlpDt5KdNiCm37CMldkCTLhONa3D35lD6pAd4kTBPH4Jub4SVcdWj792pM7wmmgE HB3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fudan.edu.cn header.s=dkim header.b=lI3M49gF; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fudan.edu.cn Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f12si5702566edl.157.2020.06.13.05.55.25; Sat, 13 Jun 2020 05:55:48 -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=@fudan.edu.cn header.s=dkim header.b=lI3M49gF; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fudan.edu.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726392AbgFMMwu (ORCPT + 99 others); Sat, 13 Jun 2020 08:52:50 -0400 Received: from mail.fudan.edu.cn ([202.120.224.10]:33944 "EHLO fudan.edu.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726021AbgFMMwt (ORCPT ); Sat, 13 Jun 2020 08:52:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fudan.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-Id; bh=oeRbaKJ4ubcIH3C117R3MYxefSczLaaLiNN/4rd1qYA=; b=l I3M49gF3ncvo/aA/VvJumF544eEhuxNDF3xeSJ0B8k5IxFZzuN4w1QtdtI0TCWaX dVEs/tPNaaloVIYqRZRdwQcy9qdWZIqp8MSj8bV+uNbpHfzgK/VELvGTulFnxsE+ 2vjM7cvTW6MQRHUHm8R55uQ9FwpSDWTtVrmQ93LZoU= Received: from localhost.localdomain (unknown [120.229.255.202]) by app1 (Coremail) with SMTP id XAUFCgCHjTEYzORemtkYAA--.21047S3; Sat, 13 Jun 2020 20:52:40 +0800 (CST) From: Xiyu Yang To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yuanxzhang@fudan.edu.cn, kjlu@umn.edu, Xiyu Yang , Xin Tan Subject: [PATCH] tty: serial_core: Fix uart_state refcnt leak when the port startup Date: Sat, 13 Jun 2020 20:52:18 +0800 Message-Id: <1592052738-95202-1-git-send-email-xiyuyang19@fudan.edu.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: XAUFCgCHjTEYzORemtkYAA--.21047S3 X-Coremail-Antispam: 1UD129KBjvJXoW7Cw1kAryUXrWkKFW5GFWfKrg_yoW8GF4kpF 43Kr9IyrWqgay8X3WDCw4vyrWY9a4qqFy2gry0kwn8trZ0qrySkr1YyrWq9F1UJry7Aryr AF4vyrs8Aa1UJF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvm14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IE rcIFxwCY02Avz4vE14v_Xr1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr 1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE 14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7 IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVW3JVWrJr1lIxAIcVC2 z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnU UI43ZEXa7VUbeOJUUUUUU== X-CM-SenderInfo: irzsiiysuqikmy6i3vldqovvfxof0/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); if (!state->xmit.buf) { state->xmit.buf = (unsigned char *) page; uart_circ_clear(&state->xmit); -- 2.7.4