From patchwork Wed Oct 9 10:48:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11180993 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96DBF1668 for ; Wed, 9 Oct 2019 10:49:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 78ABE218AC for ; Wed, 9 Oct 2019 10:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570618168; bh=iZdqq4g+rouI4y+bBonKXF4zHGiMTb9gddewiGK6aa8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=1G+TqKdMKfvb+lJx6GWwbQ0v/MATpkRBHm3dG+tW43boIOsM9cc7HZLFNQTc5Z68b ayVZpsB+6M5IpS55uoSvdtz6GKIPgz4PYOI61uNO0cmOMOhhZVqb2A7OYir/5UQfrq YZyJi5Rt0zOW/xQPG2H5IuuO/04iazh8/qjmQV7M= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730888AbfJIKtC (ORCPT ); Wed, 9 Oct 2019 06:49:02 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:35948 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727228AbfJIKtB (ORCPT ); Wed, 9 Oct 2019 06:49:01 -0400 Received: by mail-lj1-f195.google.com with SMTP id v24so1997781ljj.3; Wed, 09 Oct 2019 03:48:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hpnNo/wLrrqHWo6iUYI3k0Oeb2ujZliIeE/Ue7DBhEk=; b=fkwuwcR1x8moZJFbNg5UNTD3MZbsJ/WTv8URL2NtoOcx1zzsYuhvP+w1w129RClj5Y 9zCAHiRPSRaFDAcS+0J8pxHk5+TV9A+b7lHsqje6gjakdX3IJoEfACM9Pq2ntZmSPvWH GPOOM3t+HITiyXn/Zx6dXwyUsNScw8r0xhlblHGACvnofE7ODrgtGfHYf56tQdsbH418 X7iNOOIInxce8vXidjhTNJGoKzoCKJ4KeVBK17B4fZ+guT6gfNnIXnFupKiKWZHznuYx gXQmN+7DP6Z97ImH30b+8XOR5gU7IDAip+Iknrh+WHmWvDaWjasGiNmj5tivaPZsVUw/ VhfA== X-Gm-Message-State: APjAAAWundtuUxr3kyGaNmHxbMwsyyNOEwhfQdOifs+74c5KQD3ribjS xIAIlugd81sOUEOJh1Fqw3sR/4m6 X-Google-Smtp-Source: APXvYqyLVuDm1GTgl7a58tF/2XvgWyv4UCBSQTOtepqPe8z1dl9e1Q3Zm9HimA0SSZu8TIqRqmVuYw== X-Received: by 2002:a2e:a41a:: with SMTP id p26mr1783346ljn.15.1570618138521; Wed, 09 Oct 2019 03:48:58 -0700 (PDT) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id z26sm356497lji.79.2019.10.09.03.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Oct 2019 03:48:57 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.92.2) (envelope-from ) id 1iI9Wk-0001Yi-Ri; Wed, 09 Oct 2019 12:49:06 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Oliver Neukum , Valentin Vidic , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable , syzbot+0761012cebf7bdb38137@syzkaller.appspotmail.com Subject: [PATCH 1/6] USB: iowarrior: fix use-after-free on disconnect Date: Wed, 9 Oct 2019 12:48:41 +0200 Message-Id: <20191009104846.5925-2-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191009104846.5925-1-johan@kernel.org> References: <20191009104846.5925-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org A recent fix addressing a deadlock on disconnect introduced a new bug by moving the present flag out of the critical section protected by the driver-data mutex. This could lead to a racing release() freeing the driver data before disconnect() is done with it. Due to insufficient locking a related use-after-free could be triggered also before the above mentioned commit. Specifically, the driver needs to hold the driver-data mutex also while checking the opened flag at disconnect(). Fixes: c468a8aa790e ("usb: iowarrior: fix deadlock on disconnect") Fixes: 946b960d13c1 ("USB: add driver for iowarrior devices.") Cc: stable # 2.6.21 Reported-by: syzbot+0761012cebf7bdb38137@syzkaller.appspotmail.com Signed-off-by: Johan Hovold --- drivers/usb/misc/iowarrior.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c index f5bed9f29e56..4fe1d3267b3c 100644 --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c @@ -866,8 +866,6 @@ static void iowarrior_disconnect(struct usb_interface *interface) dev = usb_get_intfdata(interface); mutex_lock(&iowarrior_open_disc_lock); usb_set_intfdata(interface, NULL); - /* prevent device read, write and ioctl */ - dev->present = 0; minor = dev->minor; mutex_unlock(&iowarrior_open_disc_lock); @@ -878,8 +876,7 @@ static void iowarrior_disconnect(struct usb_interface *interface) mutex_lock(&dev->mutex); /* prevent device read, write and ioctl */ - - mutex_unlock(&dev->mutex); + dev->present = 0; if (dev->opened) { /* There is a process that holds a filedescriptor to the device , @@ -889,8 +886,10 @@ static void iowarrior_disconnect(struct usb_interface *interface) usb_kill_urb(dev->int_in_urb); wake_up_interruptible(&dev->read_wait); wake_up_interruptible(&dev->write_wait); + mutex_unlock(&dev->mutex); } else { /* no process is using the device, cleanup now */ + mutex_unlock(&dev->mutex); iowarrior_delete(dev); } From patchwork Wed Oct 9 10:48:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11180991 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DC8917D4 for ; Wed, 9 Oct 2019 10:49:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2F9D21929 for ; Wed, 9 Oct 2019 10:49:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570618164; bh=HUjm9AszKL05999DZto+0tUZIiQwaeUWCSGo6jd1DpU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=E8fJLAlEnjMr6oC5bYoTQhBQiIPTswshLsnCxg10yIdrvRBYqLnXh7LSiG/+S5rg+ t8tVn3g/2HRhdFp1aLr86gWDdrxnLLVK1yhcSSDisonpdBpzUtGjPgJEK6SAls4px3 Nza0cEZUhp8VDy3w1fp9kokiERDqb81l4avsHDjI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731108AbfJIKtU (ORCPT ); Wed, 9 Oct 2019 06:49:20 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:37177 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729471AbfJIKtC (ORCPT ); Wed, 9 Oct 2019 06:49:02 -0400 Received: by mail-lf1-f66.google.com with SMTP id w67so1285834lff.4; Wed, 09 Oct 2019 03:49:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I9S1LZhS7NXOvlyQeuNp2uC2+n7oyPIPQVWvy8JnR8k=; b=CqsD9cPOjWJGiC45LdabQhInhRSG6/SFcVmMlQ2sjeM9J7/EvoJiBJsuQOjlTugI5F 7ewWKeHW474+fJh/+1pVt/vyDROT7MMzuf/TQtBpgUcD1k6qjcEfopCZ2UW0d43m5fwc c7GkwLuK+YGxj+3h3vu1L95fDpUT32DHoccRV0mzTLbsUhmcUAgzbxsWxLCIQAAa4nJN v7GbGI6QxTHacOtqkh5hHW5asm/IAQxLkb06VoVsnPtEOyZi4c01XT9HHBNNZCblWcCr HljxAcxQwE2P2ay9uoShZ8RnFhY9ZnO/pskPNdkkqPYFtCRy+kQ2TdZlaMJ9SHJt+ssD 87Gg== X-Gm-Message-State: APjAAAVtPY4Km4EZruSsSkxS3oPu+s3wfQSDbZ/gqBZ1jA9QsUsUQxmK Y8sOHX9oUA1SCgCzIiSuNYA= X-Google-Smtp-Source: APXvYqwu9JjQAwNijJ26sxj1ucuo52qILAxSWiZWCaWhta33rkytYVZHMjkH/dtdQ2WwWBplYiUilA== X-Received: by 2002:a19:2394:: with SMTP id j142mr1619262lfj.13.1570618139808; Wed, 09 Oct 2019 03:48:59 -0700 (PDT) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id b6sm440699lfi.72.2019.10.09.03.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Oct 2019 03:48:57 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.92.2) (envelope-from ) id 1iI9Wk-0001Ym-UO; Wed, 09 Oct 2019 12:49:06 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Oliver Neukum , Valentin Vidic , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable Subject: [PATCH 2/6] USB: iowarrior: fix use-after-free on release Date: Wed, 9 Oct 2019 12:48:42 +0200 Message-Id: <20191009104846.5925-3-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191009104846.5925-1-johan@kernel.org> References: <20191009104846.5925-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The driver was accessing its struct usb_interface from its release() callback without holding a reference. This would lead to a use-after-free whenever debugging was enabled and the device was disconnected while its character device was open. Fixes: 549e83500b80 ("USB: iowarrior: Convert local dbg macro to dev_dbg") Cc: stable # 3.16 Signed-off-by: Johan Hovold --- drivers/usb/misc/iowarrior.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c index 4fe1d3267b3c..6841267820c6 100644 --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c @@ -243,6 +243,7 @@ static inline void iowarrior_delete(struct iowarrior *dev) kfree(dev->int_in_buffer); usb_free_urb(dev->int_in_urb); kfree(dev->read_queue); + usb_put_intf(dev->interface); kfree(dev); } @@ -764,7 +765,7 @@ static int iowarrior_probe(struct usb_interface *interface, init_waitqueue_head(&dev->write_wait); dev->udev = udev; - dev->interface = interface; + dev->interface = usb_get_intf(interface); iface_desc = interface->cur_altsetting; dev->product_id = le16_to_cpu(udev->descriptor.idProduct); From patchwork Wed Oct 9 10:48:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11180983 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D33A1864 for ; Wed, 9 Oct 2019 10:49:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E22E721848 for ; Wed, 9 Oct 2019 10:49:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570618144; bh=wj2eDkfOPT0iJrRrtTTEcXkmsC/y5MTuw6tD+LlLj0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Q+FdgycTpJapWJ+jFYpC5F6/+OeQjivUJHbT72h36mS32eIUNNPvWJoNjz7StW+Pi I5LQpOXrdpiNDgWO9BXsmJxty5TQXn3UiKLMMWCJXtFr4Vw6nRU8TT0K2xb05eNj2i r/avzqEbY7ZpxyKAEUmgYP+9IZZyrET8tJtY7WNY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730955AbfJIKtD (ORCPT ); Wed, 9 Oct 2019 06:49:03 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:44995 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729566AbfJIKtC (ORCPT ); Wed, 9 Oct 2019 06:49:02 -0400 Received: by mail-lj1-f194.google.com with SMTP id m13so1946397ljj.11; Wed, 09 Oct 2019 03:49:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Jp5IpW7NDkKcMKs+niRmVs2OZnWMfVPMeRAFv9dDYyE=; b=Ery8xEzAbcVqBP5me3PpRWNrFpfsWujNiiw/9gemzaHA/NjPDLJ8ZEv4ZkA61e99tm BUGmuWL5bFB8fHG1yjOuvumDL+TOcSqOSLd97RHCzeAAppcfYn/83FVitzTs+OeWT2nW PT8H36mwi8HTGaWmYeIzX9LpR0DdGIGcF0KbVRlpJNy2A4OEoeLJ6bKcd4bWF52WcXTo bD7IJrfhe85fuZGEKJr537qE8RdnPPHw8/31HtB4mv+KEP7qLuc5eNf91ILUHfJywV4e ashUSRyQtylZjO2KxjFdSHk6Rb3okVrblnTm5Cc4yRi8+a1xRLDn6uG2qDwJfoOSe209 twUQ== X-Gm-Message-State: APjAAAXs2a/vK9NK/sayij7tyoYOc2Oc53rD80KqQDfkOjNBm150EYAt 8+t91/+7kedeJfQWD3Nh1iU= X-Google-Smtp-Source: APXvYqzd+qokTRJTa8cKwVnJ2B2rU2tK2l5aGtYh0HbnGAeCN7FwrKcVwXSrfB/fNHMfgjfbljnyPQ== X-Received: by 2002:a2e:8e87:: with SMTP id z7mr1638949ljk.207.1570618140222; Wed, 09 Oct 2019 03:49:00 -0700 (PDT) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id c69sm368259ljf.32.2019.10.09.03.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Oct 2019 03:48:57 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.92.2) (envelope-from ) id 1iI9Wl-0001Yr-0d; Wed, 09 Oct 2019 12:49:07 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Oliver Neukum , Valentin Vidic , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable Subject: [PATCH 3/6] USB: iowarrior: fix use-after-free after driver unbind Date: Wed, 9 Oct 2019 12:48:43 +0200 Message-Id: <20191009104846.5925-4-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191009104846.5925-1-johan@kernel.org> References: <20191009104846.5925-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Make sure to stop also the asynchronous write URBs on disconnect() to avoid use-after-free in the completion handler after driver unbind. Fixes: 946b960d13c1 ("USB: add driver for iowarrior devices.") Cc: stable # 2.6.21: 51a2f077c44e ("USB: introduce usb_anchor") Signed-off-by: Johan Hovold --- drivers/usb/misc/iowarrior.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c index 6841267820c6..f405fa734bcc 100644 --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c @@ -87,6 +87,7 @@ struct iowarrior { char chip_serial[9]; /* the serial number string of the chip connected */ int report_size; /* number of bytes in a report */ u16 product_id; + struct usb_anchor submitted; }; /*--------------*/ @@ -425,11 +426,13 @@ static ssize_t iowarrior_write(struct file *file, retval = -EFAULT; goto error; } + usb_anchor_urb(int_out_urb, &dev->submitted); retval = usb_submit_urb(int_out_urb, GFP_KERNEL); if (retval) { dev_dbg(&dev->interface->dev, "submit error %d for urb nr.%d\n", retval, atomic_read(&dev->write_busy)); + usb_unanchor_urb(int_out_urb); goto error; } /* submit was ok */ @@ -770,6 +773,8 @@ static int iowarrior_probe(struct usb_interface *interface, iface_desc = interface->cur_altsetting; dev->product_id = le16_to_cpu(udev->descriptor.idProduct); + init_usb_anchor(&dev->submitted); + res = usb_find_last_int_in_endpoint(iface_desc, &dev->int_in_endpoint); if (res) { dev_err(&interface->dev, "no interrupt-in endpoint found\n"); @@ -885,6 +890,7 @@ static void iowarrior_disconnect(struct usb_interface *interface) Deleting the device is postponed until close() was called. */ usb_kill_urb(dev->int_in_urb); + usb_kill_anchored_urbs(&dev->submitted); wake_up_interruptible(&dev->read_wait); wake_up_interruptible(&dev->write_wait); mutex_unlock(&dev->mutex); From patchwork Wed Oct 9 10:48:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11180985 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2BAA117D4 for ; Wed, 9 Oct 2019 10:49:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0CD71218AC for ; Wed, 9 Oct 2019 10:49:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570618154; bh=B01r0ERXQoQn7IbBA+bn58b0ZTkmYMtZrT4YMTMiH1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=aKjFvyHfj9MrbQQv08MoY7WOQ+A/FAxnv6E/F8D+yjnuTua+dFuuU8pLowSW9aCml G99HOz11MQd2jd9PJ8aHiefyixk87KkotbeLF8dXdJx3wRsaV22pkwmDuzBqFxmC9/ YyR6kx5uYSSTbXKLLRMVH3SGbMpyFeWFsvNuE/q0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731012AbfJIKtH (ORCPT ); Wed, 9 Oct 2019 06:49:07 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:33280 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727228AbfJIKtE (ORCPT ); Wed, 9 Oct 2019 06:49:04 -0400 Received: by mail-lf1-f68.google.com with SMTP id y127so1301620lfc.0; Wed, 09 Oct 2019 03:49:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1LQbCixt1QlNE9A03/JuuzZsv5WmNTNPRYC7ctJ1dxk=; b=PWmWujvT7DwTCfrXRU3Rtgg7RUAtMigSGvLnXz1hzsq9TIffelQ1+HNYYabTBQzthB AR0/aw8L+0fQga0FC8PuTCheeQJW+YpP1CoOe5JGGSjezjsJs8EijYZkGxc27JNSFIM/ W74mKiHqbiilYRICccMqfv+tmngExxxIpzB7kiXupqldZgTc+W7TOm24AY5yH1BIUNDZ 68T4OkpKiCJH2qUKvdUBal7WxpqqOT1mQXm3p+tV0DlGPlzjbC0TsrkZsKTo8DP/eU7V Z9PKgWQeE3Hib0TQ8KYfnQjLPHCHrusYO/jgFNDLQEAoq4HKgL/cRvE1pbYfU3glrC43 pu0Q== X-Gm-Message-State: APjAAAUZThm20/C9tax6epHUvM8KLbLKrsqhhXRA9lnJxXHgy+RPIm/M /pSQApessISUVWm7uNc+Wvg= X-Google-Smtp-Source: APXvYqyNokw0VSwedSu94vAEBosXu8uHXBOyAJhAGRXwcwEHa6TifXsy+6v8MKDUDrAPh6kwTxXFhA== X-Received: by 2002:ac2:4d05:: with SMTP id r5mr1604787lfi.26.1570618141800; Wed, 09 Oct 2019 03:49:01 -0700 (PDT) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id w17sm378114lfl.43.2019.10.09.03.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Oct 2019 03:48:59 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.92.2) (envelope-from ) id 1iI9Wl-0001Yw-3W; Wed, 09 Oct 2019 12:49:07 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Oliver Neukum , Valentin Vidic , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 4/6] USB: iowarrior: drop redundant disconnect mutex Date: Wed, 9 Oct 2019 12:48:44 +0200 Message-Id: <20191009104846.5925-5-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191009104846.5925-1-johan@kernel.org> References: <20191009104846.5925-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop the redundant disconnect mutex which was introduced after the open-disconnect race had been addressed generally in USB core by commit d4ead16f50f9 ("USB: prevent char device open/deregister race"). Specifically, the rw-semaphore in core guarantees that all calls to open() will have completed and that no new calls to open() will occur after usb_deregister_dev() returns. Hence there is no need use the driver data as an inverted disconnected flag. Signed-off-by: Johan Hovold --- drivers/usb/misc/iowarrior.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c index f405fa734bcc..d844c2098e42 100644 --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c @@ -58,7 +58,6 @@ MODULE_LICENSE("GPL"); static DEFINE_MUTEX(iowarrior_mutex); static struct usb_driver iowarrior_driver; -static DEFINE_MUTEX(iowarrior_open_disc_lock); /*--------------*/ /* data */ @@ -601,16 +600,13 @@ static int iowarrior_open(struct inode *inode, struct file *file) return -ENODEV; } - mutex_lock(&iowarrior_open_disc_lock); dev = usb_get_intfdata(interface); if (!dev) { - mutex_unlock(&iowarrior_open_disc_lock); mutex_unlock(&iowarrior_mutex); return -ENODEV; } mutex_lock(&dev->mutex); - mutex_unlock(&iowarrior_open_disc_lock); /* Only one process can open each device, no sharing. */ if (dev->opened) { @@ -842,7 +838,6 @@ static int iowarrior_probe(struct usb_interface *interface, if (retval) { /* something prevented us from registering this driver */ dev_err(&interface->dev, "Not able to get a minor for this device.\n"); - usb_set_intfdata(interface, NULL); goto error; } @@ -866,16 +861,8 @@ static int iowarrior_probe(struct usb_interface *interface, */ static void iowarrior_disconnect(struct usb_interface *interface) { - struct iowarrior *dev; - int minor; - - dev = usb_get_intfdata(interface); - mutex_lock(&iowarrior_open_disc_lock); - usb_set_intfdata(interface, NULL); - - minor = dev->minor; - mutex_unlock(&iowarrior_open_disc_lock); - /* give back our minor - this will call close() locks need to be dropped at this point*/ + struct iowarrior *dev = usb_get_intfdata(interface); + int minor = dev->minor; usb_deregister_dev(interface, &iowarrior_class); From patchwork Wed Oct 9 10:48:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11180989 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF13C17D4 for ; Wed, 9 Oct 2019 10:49:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D10BB21929 for ; Wed, 9 Oct 2019 10:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570618159; bh=3BSgJs/n43Bhn9gktqoW/EpmMThVE8QNmR/TecEWfWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=t/kxoAGaJQ9aSt5nhqt/eNaOa6EmqL2sFmi93yFj5QIptzJq60s5ANpusyQjx8O2V iWz2Y0eaK+LTUwWSs8A8pacssz4drWFwtj0UYivR+0G0goFq6vUv5rpioTH75n5jYI eCYmbvBhbL2HTI3HMYM/h3ID157CVnDx3wFSwlg4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731076AbfJIKtP (ORCPT ); Wed, 9 Oct 2019 06:49:15 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:38714 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730988AbfJIKtG (ORCPT ); Wed, 9 Oct 2019 06:49:06 -0400 Received: by mail-lj1-f196.google.com with SMTP id b20so1979683ljj.5; Wed, 09 Oct 2019 03:49:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Yqwtz3pnYTZFkAJLkDd3CcxBJSehR/4/DPuBsJC1vEI=; b=jSuZPceVBXAZrD8V5lDqK15JlunJcTtrCV1bOkGzfblloeRHdbIs5OkC2xyZmEXdwb +4bFsHjePl3h1fSjOzLUIb+F0Gu1VBKL+FuTsCLTCLj+KBm60LKuodLalgwbF+8HKpAs gqT2P7vxvHYAN47UWD1PgE9w4lrnHreRkUWqwK56BVbP9WwfdWwDMuMH5IyPF6egFkm2 asgLXO4Y/Wctagbumf06A621unSVnb/65JIVmk5qLjzkktL/ywadG5VkVGH/T4VMGVNS isAAqsmej7hjC/g2gbLFrh9WZ2RJ9saiIUu08KUPB8klL5ImPOat+lopysIID75ckPm2 psug== X-Gm-Message-State: APjAAAVSxtceosmQRQu4lgy9f967ShlDApKpA25DPZDZVMx9dO7TI9nH aXCY3sxv7zccAozUXgPrXgQ= X-Google-Smtp-Source: APXvYqyZnzB7/JvvG4Aj/xXx3JeHh1OgS8DJA5y66iuhkyNtEK+2RKT8lp5KyrTW03ALpxTUgkUxKA== X-Received: by 2002:a2e:97ca:: with SMTP id m10mr346806ljj.168.1570618143045; Wed, 09 Oct 2019 03:49:03 -0700 (PDT) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id j26sm344555lja.25.2019.10.09.03.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Oct 2019 03:49:01 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.92.2) (envelope-from ) id 1iI9Wl-0001Z1-6i; Wed, 09 Oct 2019 12:49:07 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Oliver Neukum , Valentin Vidic , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 5/6] USB: iowarrior: drop redundant iowarrior mutex Date: Wed, 9 Oct 2019 12:48:45 +0200 Message-Id: <20191009104846.5925-6-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191009104846.5925-1-johan@kernel.org> References: <20191009104846.5925-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop the redundant iowarrior mutex introduced by commit 925ce689bb31 ("USB: autoconvert trivial BKL users to private mutex") which replaced an earlier BKL use. The lock serialised calls to open() against other open() and ioctl(), but neither is needed. Signed-off-by: Johan Hovold --- drivers/usb/misc/iowarrior.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c index d844c2098e42..ad29ef51e53f 100644 --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c @@ -54,9 +54,6 @@ MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); -/* Module parameters */ -static DEFINE_MUTEX(iowarrior_mutex); - static struct usb_driver iowarrior_driver; /*--------------*/ @@ -480,8 +477,6 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd, if (!buffer) return -ENOMEM; - /* lock this object */ - mutex_lock(&iowarrior_mutex); mutex_lock(&dev->mutex); /* verify that the device wasn't unplugged */ @@ -574,7 +569,6 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd, error_out: /* unlock the device */ mutex_unlock(&dev->mutex); - mutex_unlock(&iowarrior_mutex); kfree(buffer); return retval; } @@ -589,22 +583,18 @@ static int iowarrior_open(struct inode *inode, struct file *file) int subminor; int retval = 0; - mutex_lock(&iowarrior_mutex); subminor = iminor(inode); interface = usb_find_interface(&iowarrior_driver, subminor); if (!interface) { - mutex_unlock(&iowarrior_mutex); printk(KERN_ERR "%s - error, can't find device for minor %d\n", __func__, subminor); return -ENODEV; } dev = usb_get_intfdata(interface); - if (!dev) { - mutex_unlock(&iowarrior_mutex); + if (!dev) return -ENODEV; - } mutex_lock(&dev->mutex); @@ -628,7 +618,6 @@ static int iowarrior_open(struct inode *inode, struct file *file) out: mutex_unlock(&dev->mutex); - mutex_unlock(&iowarrior_mutex); return retval; } From patchwork Wed Oct 9 10:48:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11180987 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 089891668 for ; Wed, 9 Oct 2019 10:49:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D3D2821835 for ; Wed, 9 Oct 2019 10:49:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570618154; bh=IfM4sXsvKneSTjzc9pG1+JjgAAbQBdAGhjrDFZmRyxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=m7XsCV7ASZecEJ+FzAMzNhFKyO4Qx72tby1TU0TkV+fq1O1tOnIZDLt4T7PVRabq1 Xi19kBlSmcSiMozfiPEU620JRxC2egrQQjsebIffCEC+A1B8F8S9sKwvy+88XkAFSk ccZ85KDv2nkeHH+kxyP+l3vndF6fWJyHRg2EldNw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730998AbfJIKtH (ORCPT ); Wed, 9 Oct 2019 06:49:07 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:32827 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730936AbfJIKtE (ORCPT ); Wed, 9 Oct 2019 06:49:04 -0400 Received: by mail-lj1-f194.google.com with SMTP id a22so2015033ljd.0; Wed, 09 Oct 2019 03:49:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ysqjawGWGxhBElqwciD5mCdMVjymryIh3Vgfdb6+Ybk=; b=Ky4pkrfsT56P7zj+dT/LonYWtFW3qiZLR3t9kS5t6E5KVAbxQrYSanNNBq8tOd+Wsn QGOdEJTDm3Epo2BzlZtYCIhPGaVQy0f4fq4wce1Z7TPVngFMbgv5JQcD547TkuNfpL2V Ib35DNfnW/qdAHIvZNMxbR36C4MT6XjQ9nYsVW1/0G1CLhLpZEYG8eQnepCGt3K6NSyW x+LLW7ecK2n+VebtZXV7Br/v6ZU2T+jKn4Ay70RiUM4T0PEDgfZBVHP6tlFgp1QOVF4N ZSTEUpOkDD0i4AXwOsP+Kcrj1kocDKgcQK8SGuxl/3tI8gZ1aJrHdIVxCzTAPyH6PvH3 vpAA== X-Gm-Message-State: APjAAAWrW+Wu1hM+mHE2pVt3mdgdxBXRL2VqFIc1KipaJWzpxq1t+dOD pUZB3VYQjzgcAhqaMakV7BfcYU9G X-Google-Smtp-Source: APXvYqxR7CFmMBUEG7pNzCeUKgPWwONBSYUrHcPPm9rFSyUklLhkzYPOXveucArAshfDN8NlssTqMQ== X-Received: by 2002:a2e:9d06:: with SMTP id t6mr1889394lji.253.1570618142306; Wed, 09 Oct 2019 03:49:02 -0700 (PDT) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id c4sm377448lfm.4.2019.10.09.03.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Oct 2019 03:49:00 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.92.2) (envelope-from ) id 1iI9Wl-0001Z6-9y; Wed, 09 Oct 2019 12:49:07 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Oliver Neukum , Valentin Vidic , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 6/6] USB: iowarrior: use pr_err() Date: Wed, 9 Oct 2019 12:48:46 +0200 Message-Id: <20191009104846.5925-7-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191009104846.5925-1-johan@kernel.org> References: <20191009104846.5925-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Replace the one remaining printk with pr_err(). Signed-off-by: Johan Hovold --- drivers/usb/misc/iowarrior.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c index ad29ef51e53f..dce44fbf031f 100644 --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c @@ -587,7 +587,7 @@ static int iowarrior_open(struct inode *inode, struct file *file) interface = usb_find_interface(&iowarrior_driver, subminor); if (!interface) { - printk(KERN_ERR "%s - error, can't find device for minor %d\n", + pr_err("%s - error, can't find device for minor %d\n", __func__, subminor); return -ENODEV; }