Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp817237ybl; Wed, 11 Dec 2019 07:59:01 -0800 (PST) X-Google-Smtp-Source: APXvYqwPFu1/eSBtHHEftoYeLHF40x1XW1N+56kctL+B9ziHWn90rWwznxJtNCCQop51LTj9acHx X-Received: by 2002:a05:6830:10d7:: with SMTP id z23mr2789755oto.114.1576079940983; Wed, 11 Dec 2019 07:59:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576079940; cv=none; d=google.com; s=arc-20160816; b=Ub3NlRpcNuM2Tah7JFX1gZW/qTk8zhSpPCkTzDs/DTPotX5LjD4wGcV+yDcI8f9IBG O0Behd88jRH/wzwk8szbDrfqofe97uYEdMsYuYhJ49qi3sPMxICwk0thmFUBuIb9pf8L PpQpZEkxvhqhjiHZ1z4XvbXgj4gjTfV1d4cp5lqTi3k6vW6VwBj8im5sL3iuFs73URPj QcoKNe0WtI6yc7GNCekNJ21S0iYJxLYspZThdDfuxN/RV9FwwxydvaNzIgTMVGT8mOlr G5eRl9u83fKNrQFFb0QYneos/KhHcVlkl5HZQ/OnCpL/wBNWnUBStpyBH6gceitXSBPk S0hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=J59Kz9DsMaIblzWbnU9MwRoXXqQWDwTn+gkMhwDVeI0=; b=XHWhiGMNEaia+unwK1B3HBda2GiqGOMGLYt2j3L3WHJqGMdMzJtQAViACrjnDrLAol 0RlR7hxlqWQBhJFMzALlP40rtu4eUKmcaPos2dK3mqpW+UmpyDCgjajTY/kkL/ee1oqo xVPYi+Se9eudFXxNlZ3PU3/k69X+zA+QlS4ItbHkYGuyemqF3zWY0a+yv54ntMEyoGGK lTMm+DrkeGuZWMZBaqDXiPAWvrIALvXNPQVa6Rplhmg16EQGyQc5WxvF0dHGMeH0WG6c 1eqM4OWEDK+QZHPnDuiTzkHpvzFCAdMrbnVT2+gnJ6CK5SOL4Gvp0AyMj3hqvTXTLcdP vCpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tQIUOi2x; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p26si1291254oto.240.2019.12.11.07.58.48; Wed, 11 Dec 2019 07:59:00 -0800 (PST) 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=@kernel.org header.s=default header.b=tQIUOi2x; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731676AbfLKPOy (ORCPT + 99 others); Wed, 11 Dec 2019 10:14:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:38174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729609AbfLKPNy (ORCPT ); Wed, 11 Dec 2019 10:13:54 -0500 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 C0E0024656; Wed, 11 Dec 2019 15:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077234; bh=ZR19IDXpPk3hAdCKhmbkx3xf7pwKHMAIoGz17JSoSRQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tQIUOi2x0k3nsiEF62uSST/ZXTW92tA7P84c/adRryitB3J1+B4XBC3BevYu3BmUA Ly0v+0t0olW2dip6So/cunjE8m7lvM9YojSMjqC8wVshN/T58y9AxJxanHjG3pNul7 clE7eaK7CHvzbpTiNuFkU5Cub7CTG27RrVS9T/AY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wolfgang Grandegger , Marc Kleine-Budde , David Miller , Oliver Hartkopp , Lukas Bulwahn , Jouni Hogander Subject: [PATCH 5.3 067/105] can: slcan: Fix use-after-free Read in slcan_open Date: Wed, 11 Dec 2019 16:05:56 +0100 Message-Id: <20191211150248.307148093@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jouni Hogander commit 9ebd796e24008f33f06ebea5a5e6aceb68b51794 upstream. Slcan_open doesn't clean-up device which registration failed from the slcan_devs device list. On next open this list is iterated and freed device is accessed. Fix this by calling slc_free_netdev in error path. Driver/net/can/slcan.c is derived from slip.c. Use-after-free error was identified in slip_open by syzboz. Same bug is in slcan.c. Here is the trace from the Syzbot slip report: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x197/0x210 lib/dump_stack.c:118 print_address_description.constprop.0.cold+0xd4/0x30b mm/kasan/report.c:374 __kasan_report.cold+0x1b/0x41 mm/kasan/report.c:506 kasan_report+0x12/0x20 mm/kasan/common.c:634 __asan_report_load8_noabort+0x14/0x20 mm/kasan/generic_report.c:132 sl_sync drivers/net/slip/slip.c:725 [inline] slip_open+0xecd/0x11b7 drivers/net/slip/slip.c:801 tty_ldisc_open.isra.0+0xa3/0x110 drivers/tty/tty_ldisc.c:469 tty_set_ldisc+0x30e/0x6b0 drivers/tty/tty_ldisc.c:596 tiocsetd drivers/tty/tty_io.c:2334 [inline] tty_ioctl+0xe8d/0x14f0 drivers/tty/tty_io.c:2594 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:509 [inline] do_vfs_ioctl+0xdb6/0x13e0 fs/ioctl.c:696 ksys_ioctl+0xab/0xd0 fs/ioctl.c:713 __do_sys_ioctl fs/ioctl.c:720 [inline] __se_sys_ioctl fs/ioctl.c:718 [inline] __x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:718 do_syscall_64+0xfa/0x760 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x49/0xbe Fixes: ed50e1600b44 ("slcan: Fix memory leak in error path") Cc: Wolfgang Grandegger Cc: Marc Kleine-Budde Cc: David Miller Cc: Oliver Hartkopp Cc: Lukas Bulwahn Signed-off-by: Jouni Hogander Cc: linux-stable # >= v5.4 Acked-by: Oliver Hartkopp Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/slcan.c | 1 + 1 file changed, 1 insertion(+) --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -613,6 +613,7 @@ err_free_chan: sl->tty = NULL; tty->disc_data = NULL; clear_bit(SLF_INUSE, &sl->flags); + slc_free_netdev(sl->dev); free_netdev(sl->dev); err_exit: