From patchwork Mon May 7 17:11:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 909858 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linutronix.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XdZsQusM"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40fq132CFJz9ryk for ; Tue, 8 May 2018 03:12:07 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=C1MGbLjtTnTVIZi9956wPZmu32btg+v7ymyjq2HvNOw=; b=XdZsQusMfj3Lrj qs5ojTz8Ku2IBPTSIIRzYCNjHJMtBxB9cdzUcxJW1FKnjbX6yJONEfgFeEMPDo9TF1/ow1Bk/TVJJ 1rlklAJwgdPDKIR/JA0lQwNFWgMARLq/BFkpnjXNdveIMlIS8oVJGZSo14OokyerjT8t6sND2bRdH HTtA6rN0rZgVjk3a6B5oDNSDgmI8klI5jdn2A2DpvFgdfbM7QcYVEKxbXDqQ1kpr+P5v1hSdbBUOz fIyRx9aQpeDbNFDxLT1GXfs1vZygYqICuW4r0n/86mCBzpTDAB8aw0osm+EDlFXcHuQeXMW3FeDn9 teKoJLX3y5NrKvfF91pg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fFjgB-0007Vh-Dr; Mon, 07 May 2018 17:12:03 +0000 Received: from galois.linutronix.de ([2a01:7a0:2:106d:700::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fFjg0-0007OJ-0B for linux-arm-kernel@lists.infradead.org; Mon, 07 May 2018 17:11:57 +0000 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1fFjfe-0001Lf-Pf; Mon, 07 May 2018 19:11:30 +0200 Date: Mon, 7 May 2018 19:11:30 +0200 From: Sebastian Andrzej Siewior To: Rob Herring Subject: [PATCH v3] tty/serial: atmel: use port->name as name in request_irq() Message-ID: <20180507171130.iba7nm3tgfyxgabs@linutronix.de> References: <20180426151222.6vw67lwqmu6ffgnw@linutronix.de> <0dbf4a4c-71d4-6456-67b9-d4d202acffb7@sorico.fr> <20180502191632.tgda4g5v3rhncx7c@linutronix.de> <4f3f6e7c-2806-1749-1523-72d5c8eb8229@sorico.fr> <20180503124410.n6ze2ngwv6ekjhdr@linutronix.de> <921729c6-7c3f-11cd-8634-044a5c52f810@sorico.fr> <80203f75-f38e-6214-e9b6-8512c5941647@sorico.fr> <20180504081447.enontsm6jod4xa6g@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180323 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180507_101152_246572_B93D6379 X-CRM114-Status: GOOD ( 13.35 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [2a01:7a0:2:106d:700:0:0:1 listed in] [list.dnswl.org] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Peter Hurley , Richard Genoud , Greg Kroah-Hartman , "open list:SERIAL DRIVERS" , Jiri Slaby , Thomas Gleixner , "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org I was puzzled while looking at /proc/interrupts and random things showed up between reboots. This occurred more often but I realised it later. The "correct" output should be: |38: 11861 atmel-aic5 2 Level ttyS0 but I saw sometimes |38: 6426 atmel-aic5 2 Level tty1 and accounted it wrongly as correct. This is use after free and the former example randomly got the "old" pointer which pointed to the same content. With SLAB_FREELIST_RANDOM and HARDENED I even got |38: 7067 atmel-aic5 2 Level E=Started User Manager for UID 0 or other nonsense. As it turns out the tty, pointer that is accessed in atmel_startup(), is freed() before atmel_shutdown(). It seems to happen quite often that the tty for ttyS0 is allocated and freed while ->shutdown is not invoked. I don't do anything special - just a systemd boot :) Use dev_name(&pdev->dev) as the IRQ name for request_irq(). This exists as long as the driver is loaded so no use-after-free here. Cc: stable@vger.kernel.org Fixes: 761ed4a94582 ("tty: serial_core: convert uart_close to use tty_port_close") Acked-by: Richard Genoud Acked-by: Rob Herring Signed-off-by: Sebastian Andrzej Siewior --- v2…v3: - Add Acked-by - replace port->name -> dev_name(&pdev->dev) to ease work for backporters (suggested by Rob) v1…v2: add Fixes after bisect. drivers/tty/serial/atmel_serial.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index e287fe8f10fc..55b3eff148b1 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -1757,7 +1757,6 @@ static int atmel_startup(struct uart_port *port) { struct platform_device *pdev = to_platform_device(port->dev); struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); - struct tty_struct *tty = port->state->port.tty; int retval; /* @@ -1772,8 +1771,8 @@ static int atmel_startup(struct uart_port *port) * Allocate the IRQ */ retval = request_irq(port->irq, atmel_interrupt, - IRQF_SHARED | IRQF_COND_SUSPEND, - tty ? tty->name : "atmel_serial", port); + IRQF_SHARED | IRQF_COND_SUSPEND, + dev_name(&pdev->dev), port); if (retval) { dev_err(port->dev, "atmel_startup - Can't get irq\n"); return retval;