Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933102AbdHVOvR (ORCPT ); Tue, 22 Aug 2017 10:51:17 -0400 Received: from mail.ispras.ru ([83.149.199.45]:44546 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932959AbdHVOvQ (ORCPT ); Tue, 22 Aug 2017 10:51:16 -0400 From: Anton Volkov Subject: Possible double free in iowarrior.ko To: lucht@codemercs.com, johan@kernel.org Cc: Greg KH , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org, Alexey Khoroshilov Message-ID: <660deb7a-53d0-133c-02dc-c9b4a0de9ae6@ispras.ru> Date: Tue, 22 Aug 2017 17:51:14 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1340 Lines: 37 Hello. While searching for races in the Linux kernel I've come across "drivers/usb/misc/iowarrior.ko" module. Here are questions that I came up with while analyzing results. Lines are given using the info from Linux v4.12. Consider the following case: Thread 1: Thread 2: iowarrior_release iowarrior_disconnect mutex_lock(&dev->mutex) dev->present = 0 (iowarrior.c: line 889) mutex_lock(&dev->mutex) mutex_unlock(&dev->mutex) dev->opened = 0 (iowarrior.c: line 666) if(dev->opened){ if(dev->present){ //dev->opened == 0 //dev->present ==0 } else { } else { mutex_unlock(&dev->mutex) iowarrior_delete(dev) iowarrior_delete(dev) } } In this case double free of several pointers inside iowarrior_delete becomes possible and no calls to usb_kill_urb() and wake_up_interruptible() are present. Is this feasible from your point of view? If so, maybe it is a good idea to move mutex_unlock(&dev->mutex) in iowarrior_disconnect() further down like in iowarrior_release() in both 'if' branches? Thank you for your time -- Anton Volkov Linux Verification Center, ISPRAS web: http://linuxtesting.org e-mail: avolkov@ispras.ru