From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from www262.sakura.ne.jp ([202.181.97.72]:42344 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728475AbeH2TAy (ORCPT ); Wed, 29 Aug 2018 15:00:54 -0400 Subject: Re: [PATCH v2] n_tty: Protect tty->disc_data using refcount. To: Jiri Slaby , gregkh@linuxfoundation.org, jslaby@suse.com Cc: syzbot , linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Alexander Viro , linux-fsdevel References: <001a113ed31a122ced0568cc6be1@google.com> <35d649ce-0c22-f839-aa4d-19733bf31a9c@I-love.SAKURA.ne.jp> <83fdde07-2f8e-8d20-30a2-a8f0804a5044@I-love.SAKURA.ne.jp> <8e83cd9a-e28c-a9f4-5f47-98f2046a5dfb@I-love.SAKURA.ne.jp> <021343cd-dc28-9889-7656-e624861bc770@suse.cz> From: Tetsuo Handa Message-ID: Date: Thu, 30 Aug 2018 00:02:30 +0900 MIME-Version: 1.0 In-Reply-To: <021343cd-dc28-9889-7656-e624861bc770@suse.cz> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On 2018/08/29 22:53, Jiri Slaby wrote: > On 07/24/2018, 05:22 PM, Tetsuo Handa wrote: >> From 118c64e86641a97d44dec39e313a95b12d9bc3b2 Mon Sep 17 00:00:00 2001 >> From: Tetsuo Handa >> Date: Wed, 25 Jul 2018 00:15:18 +0900 >> Subject: [PATCH v2] n_tty: Protect tty->disc_data using refcount. >> >> syzbot is reporting NULL pointer dereference at n_tty_set_termios() [1]. >> This is because ioctl(TIOCVHANGUP) versus ioctl(TCSETS) can race. >> >> Since we don't want to introduce new locking dependency, this patch >> converts "struct n_tty_data *ldata = tty->disc_data;" in individual >> function into a function argument which follows "struct tty *", and >> holds tty->disc_data at each "struct tty_ldisc_ops" hook using refcount >> in order to ensure that memory which contains "struct n_tty_data" will >> not be released while processing individual function. > > This does not look correct and is way too complicated. ioctls should not > be called while changing/killing/hanging/whatever a ldisc. But there is > one missing lock in tty_reopen. > > So does the attached patch helps instead? > > thanks, > That patch seems to help avoiding crashes. (You can use #syz test: command.) But I think you need to check tty_ldisc_lock() return value...