Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3361126imm; Tue, 17 Jul 2018 03:36:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe/chJNxoB0bXaayOOQ4ejElCND0tEZIOt/qvYBYmLVzYfCsvZl4AgpOtMhtQmT3CbnOIQ0 X-Received: by 2002:a65:64c6:: with SMTP id t6-v6mr1048342pgv.223.1531823789063; Tue, 17 Jul 2018 03:36:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531823789; cv=none; d=google.com; s=arc-20160816; b=ulcAU9KUyk9MmYMOmgzo12lNVicBCD4QJ/9GiTIeRsyM0qURUd1+Y7Xagh7Yygm8kt YCpdx45x5jV/tr/0Dz5iX8nC4wX8v4T3kAfEzmmFsWcUayH1w74+FZkE6vdsyall6pPe Y6mTEhr7e1EqbK7ygtU9fpLA/xso3gQKdY0qDiJ0uBV57o1mzeQPOvFxifmqmH4Yf0Sl XZbpkI6f4dJ1yv7fEToy70m2yNIJLzvmnzAKHNzL3RMaZBMmd3iYorro8r6CnrvP9w8W 7f9UjjXRcQ3aFWyLZvy7fVloPFQOPVXYrc4u5axhQZUJhC3XYWwkHzPLeXs6mm11Hi9u hGCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=vBuNjniP815EcWsfw2XvBXHwvfQQYauua7PZyy9IUX8=; b=AhTUSmPCLckZcDOP9pR09CFez8qu9nEQ1B5NHX9vTHst7dFZRK+VX80tSj9L5WyBpP xSQlDcvT2sP//BBD/Lq6J4ps6uOsyeksnqILmsl8nJv4OgaFio7FQ5yFQaErXto5reTB eQqJ5kwCq0h8lnVD//BGQyBggJmGlPAog65tk+yzwopuje+nkB7MENNIqTMb7xuF/89T AGOiMZ6SCm79BowPyKaT0k61olsXSw+ASJpX6S5f/eKEu/YggxIGF/AD5hfYusutaF1S dQi4Uw1X/BM6Y4PPOsSq+oK7GB1uGVAkPMKog7DesOyc3Sxd+h4YUZTTwjJBsYcHXabf esvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=U+BTnApS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x19-v6si604030pgl.660.2018.07.17.03.36.14; Tue, 17 Jul 2018 03:36:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=U+BTnApS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730882AbeGQLHe (ORCPT + 99 others); Tue, 17 Jul 2018 07:07:34 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:33080 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730003AbeGQLHe (ORCPT ); Tue, 17 Jul 2018 07:07:34 -0400 Received: by mail-oi0-f67.google.com with SMTP id l10-v6so1102881oii.0; Tue, 17 Jul 2018 03:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=vBuNjniP815EcWsfw2XvBXHwvfQQYauua7PZyy9IUX8=; b=U+BTnApS1I+17pzbKCMDgwhcbP3KL8IsBvrRMAIftxJ6CKxzTDXgPhX9zC7NNSKoTK XDXGZviZ15c/l4YnzmScpFaw69epesRf5VLTWJZzp9xk9Hgi0EKNaTS1aCxofdmiGicK S9vsoNfq4+OKRxpcighDY+J4m8u2VT8rflSkX0cs3LFAe+Di+6Ni2VHnUTUcdTDq7BJN 58ldcfMPU3HrWRDGVLOXfSj9jrzXiWhAKhZh5PwWwJthUnI4DJSMHpYoXQGUDIxGtIuK +ziiXUU9qVNqKG6MEQvlf8M7wpkMgCdZVLq76lYx6lJYu2JiNe2citeiLozPDRMQwBsK ikiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=vBuNjniP815EcWsfw2XvBXHwvfQQYauua7PZyy9IUX8=; b=n+CwpeCQI2o8cl7lizaIIsl8StOKyQhM1/T04vA773b0fFPnTAN9Akt8HWFDtgzzaH wMLb8LFNfhRBYxlT2Va3HfuRoclHGj/NPiTHwDap6aJC2TD43m47UEu7+kWtXQ37Sfhw /seYE04gFgxdk0q1x54UcLujXognArwM77FDoWUhTIt5UeyN0b+dmLOj28Eu2yDyoxUd On0XC2FD9YLpaWogySTGoi42D2m60yUYBPZGoar2u8CmkUuEGRXky9rxRS/Im94h8MdY 7Jn1945Yupw/PTeBarBboeubqpqvplWgsMvHubR8w9Q+KmeTM3Ewut8Z7v5bF61WjeIC Z0Rw== X-Gm-Message-State: AOUpUlEE/lWxmW2dD3tm70vAeTud/z6AfgLFcdSnCRNgEU8JjB/7bUlU jrVxsF2ibYkRZtqUhRLMRADRGYD8LmLslf6VCQ== X-Received: by 2002:aca:a982:: with SMTP id s124-v6mr1095664oie.80.1531823735114; Tue, 17 Jul 2018 03:35:35 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4a:761e:0:0:0:0:0 with HTTP; Tue, 17 Jul 2018 03:35:34 -0700 (PDT) In-Reply-To: <20180717085810.23502-1-geert+renesas@glider.be> References: <20180717085810.23502-1-geert+renesas@glider.be> From: Ulrich Hecht Date: Tue, 17 Jul 2018 12:35:34 +0200 Message-ID: Subject: Re: [PATCH] serial: sh-sci: Fix use-after-free on subsequent port startup To: Geert Uytterhoeven Cc: Chris Brandt , Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, Linux-Renesas , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 17, 2018 at 10:58 AM, Geert Uytterhoeven wrote: > sci_request_irq() checks port->irqstr[j] for a NULL pointer, to decide > if a fallback interrupt name string should be allocated or not. > > While this string is freed during port shutdown, the pointer is not > zeroed. Hence on a subsequent startup of the port, it will still be > pointing to the freed memory, leading to e.g. > > WARNING: CPU: 0 PID: 404 at fs/proc/generic.c:388 __proc_create+0xbc/0x260 > name len 0 > > or to a crash (the latter is more likely with CONFIG_DEBUG_SLAB=y, due > to the poisoning of freed memory). > > Instead of zeroeing the pointer at multiple places, preinitialize > port->irqstr[j] to zero to fix this. > > Fixes: 8b0bbd956228ae87 ("serial: sh-sci: Add support for R7S9210") > Signed-off-by: Geert Uytterhoeven > --- > drivers/tty/serial/sh-sci.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c > index 5808edfe3f7be404..f8e53ac5c17dfb94 100644 > --- a/drivers/tty/serial/sh-sci.c > +++ b/drivers/tty/serial/sh-sci.c > @@ -1872,6 +1872,7 @@ static int sci_request_irq(struct sci_port *port) > } > > desc = sci_irq_desc + i; > + port->irqstr[j] = NULL; > if (SCIx_TEIDRI_IRQ_EXISTS(port)) { > /* > * ERI and BRI are muxed, just register ERI and > -- > 2.17.1 > Reviewed-by: Ulrich Hecht CU Uli