From patchwork Sun Oct 29 11:56:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 10031373 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7EBA960249 for ; Sun, 29 Oct 2017 11:57:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7415C28824 for ; Sun, 29 Oct 2017 11:57:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67F2528828; Sun, 29 Oct 2017 11:57:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E624A28826 for ; Sun, 29 Oct 2017 11:57:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751381AbdJ2L5Y (ORCPT ); Sun, 29 Oct 2017 07:57:24 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:43855 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750848AbdJ2L5W (ORCPT ); Sun, 29 Oct 2017 07:57:22 -0400 Received: by mail-lf0-f67.google.com with SMTP id a16so11842996lfk.0; Sun, 29 Oct 2017 04:57:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=bt0a7Fk53NOte18MjfjRVeQ2ZE79DZ1q4KByg3ekjdw=; b=YE/6yPV+99jgMpyQmk+uo0fzLQQORNEtgHSIZnFdD80bFP7pdCKr212s8TMfXavynM sUE/2NnICoCdEe9Wc3yDA1ZTFEDC2TqiwER16oD8OzWGA/JuOwJovnkLMy4c8ifMobDK IMUMd5lJ4OftMw73DOhkp5CaidEGhxL6NWEXWDAgKQmSRvr9yRJtgdQD4u2rExTwqapg pJuzx7kBnktJlLtKhQbk9AzNH8P5mfv/YjbR/J77g9vfLo/CLuiXOf4elJLfFgDdGlvb h/odYAQ+4wxC3f3ASOy/m+iIjKp6DsiQj6+NpccXqfnqaVbWQUNIuRkF+HUdEmN3CuJz 2adQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=bt0a7Fk53NOte18MjfjRVeQ2ZE79DZ1q4KByg3ekjdw=; b=eg1jxhsf0YVIWVNoovFpDcl4BwShn+H08PNpji8UaNwRzVwAjrvoxertvzvrV2c3ne 54bA9RetUWIaAp/YdyDWw5yyzAPjeUIP08D5mBheyPbeboVejb/J12HODT9eTKLYyD/H wReGwqaqmHH7DnPi71rZTjq5qK0vh+IY1O5z7RS/SFYAwEE80Qko59iEdGVsUVGFoEaE SpikVGxT1beroAa/4ryUxELg/p5LYz4HQus+PFf3oeNp6yr0sXEMxcmg6v/ftTPx7qS8 GZiRWMeMj959sTa/e1M7ZVmptyZs2jwcPXCwpnQlRjeuiHJCUMsHVqOvQ8bTd9VHf8Uh pDXA== X-Gm-Message-State: AMCzsaW8SCUUvAPjvVJCIeTcz8LeKolzicch5VSkOTXgo5GUw5ayyDgH TgQGeoCv+YrqTnzOEEesD+k= X-Google-Smtp-Source: ABhQp+RDBrv0liyvQses+kAedJQBAWsIWnj6rwXQAw2np7pnWotIAC4NI6ifjl5LYn8MLUbVs3ztUQ== X-Received: by 10.25.21.229 with SMTP id 98mr1753564lfv.93.1509278240994; Sun, 29 Oct 2017 04:57:20 -0700 (PDT) Received: from xi.terra (c-fab8e655.07-184-6d6c6d4.cust.bredbandsbolaget.se. [85.230.184.250]) by smtp.gmail.com with ESMTPSA id d15sm2901522ljd.71.2017.10.29.04.57.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 04:57:19 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.89) (envelope-from ) id 1e8mDN-0008R9-UD; Sun, 29 Oct 2017 12:57:17 +0100 From: Johan Hovold To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable , Suniel Mahesh , Karthik Tummala Subject: [PATCH 1/3] spi: fix use-after-free at controller deregistration Date: Sun, 29 Oct 2017 12:56:23 +0100 Message-Id: <20171029115625.32385-1-johan@kernel.org> X-Mailer: git-send-email 2.14.3 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The controller is typically freed as part of device_unregister() so store the bus id before deregistration to avoid use-after-free when the id is later released. Fixes: 9b61e302210e ("spi: Pick spi bus number from Linux idr or spi alias") Cc: stable # 4.13 Cc: Suniel Mahesh Cc: Karthik Tummala Signed-off-by: Johan Hovold --- drivers/spi/spi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index e8b5a5e21b2e..3ff0ee88c467 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2245,11 +2245,12 @@ static int __unregister(struct device *dev, void *null) void spi_unregister_controller(struct spi_controller *ctlr) { struct spi_controller *found; + int id = ctlr->bus_num; int dummy; /* First make sure that this controller was ever added */ mutex_lock(&board_lock); - found = idr_find(&spi_master_idr, ctlr->bus_num); + found = idr_find(&spi_master_idr, id); mutex_unlock(&board_lock); if (found != ctlr) { dev_dbg(&ctlr->dev, @@ -2269,7 +2270,7 @@ void spi_unregister_controller(struct spi_controller *ctlr) device_unregister(&ctlr->dev); /* free bus id */ mutex_lock(&board_lock); - idr_remove(&spi_master_idr, ctlr->bus_num); + idr_remove(&spi_master_idr, id); mutex_unlock(&board_lock); } EXPORT_SYMBOL_GPL(spi_unregister_controller);