From patchwork Fri Oct 13 12:45:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 10004685 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 9B54860360 for ; Fri, 13 Oct 2017 13:03:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E6D023201 for ; Fri, 13 Oct 2017 13:03:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8373B29002; Fri, 13 Oct 2017 13:03:52 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable 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 15D6423201 for ; Fri, 13 Oct 2017 13:03:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758206AbdJMNDf (ORCPT ); Fri, 13 Oct 2017 09:03:35 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:46898 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757833AbdJMMrK (ORCPT ); Fri, 13 Oct 2017 08:47:10 -0400 Received: by mail-wm0-f67.google.com with SMTP id m72so21262538wmc.1 for ; Fri, 13 Oct 2017 05:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aJ1LJwTYOwVcF1eiB/ryHl6Sy+xsXucahAKA8w62pQU=; b=MboTBv1rg35GPwANuUqcD8mvZodZmpxmgB1XGSBnHt1MX5zcmaQ5iaosjtWPVwkvqO 8DfV9+CuMIF5nNi1gwq8fubM3ZTPbVzKE3Z1g3qHtJW90LtoVwYmis6FKWoVXVJloKGv NlE0BwNdtphOplYki8pI0QPgYsfafKOA4Z+Fs= 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=aJ1LJwTYOwVcF1eiB/ryHl6Sy+xsXucahAKA8w62pQU=; b=nUqisYigWf7zUM595qS7TrAHA00QqoKnI79+yNQOIzgFLnjCseDs3SJksQYlA+3RBh Ewxpsb9BWYNDPWgukJ47TatNE4E9THePMaZzlPT3snIE8CMgUZGrBsJJEFqy0bxDyhDg JooF7TbOp92M6sh1sxyBw5JdV5tlMBAzS//eVIJUPoerRrByAij7DVy4K+mD3jKIPf1N nXut2rFHNa3eYDsimGce508CQhy9V6M2CuRNzfmGJuFDvdh4PxlrX5sEbMejGlRf4GqC xYxWxwLmdgUIjuXWjKRhgHI0R1g09gj3yHkDN9cLmwmOc0jgvyV0PkpT56pHK/g96pss qAtg== X-Gm-Message-State: AMCzsaX+YmCPmhsTYoAS+GZi8zvzCbyRSXJkpzm7Qv2FXskm/YsSUAQJ 4L2QzXQkJlAeRh3jap8OWOS2Dw== X-Google-Smtp-Source: AOwi7QDlZOAE9qefX7+2+0R/ph1jtq7jKgwVOqOxGF2iPGddkvXugB9GElTcibQAn/pYtx85SOqYNQ== X-Received: by 10.80.151.47 with SMTP id c44mr2037424edb.139.1507898829482; Fri, 13 Oct 2017 05:47:09 -0700 (PDT) Received: from skyninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id p91sm735012edp.69.2017.10.13.05.47.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Oct 2017 05:47:08 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Rakesh Pandit , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [GIT PULL 03/58] lightnvm: protect target type list with correct locks Date: Fri, 13 Oct 2017 14:45:52 +0200 Message-Id: <20171013124647.32668-4-m@bjorling.me> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20171013124647.32668-1-m@bjorling.me> References: <20171013124647.32668-1-m@bjorling.me> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rakesh Pandit nvm_tgt_types list was protected by wrong lock for NVM_INFO ioctl call and can race with addition or removal of target types. Also unregistering target type was not protected correctly. Fixes: 5cd907853 ("lightnvm: remove nested lock conflict with mm") Signed-off-by: Rakesh Pandit Reviewed-by: Javier González Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index c490711..ee2b6d7 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -589,9 +589,9 @@ void nvm_unregister_tgt_type(struct nvm_tgt_type *tt) if (!tt) return; - down_write(&nvm_lock); + down_write(&nvm_tgtt_lock); list_del(&tt->list); - up_write(&nvm_lock); + up_write(&nvm_tgtt_lock); } EXPORT_SYMBOL(nvm_unregister_tgt_type); @@ -1195,7 +1195,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg) info->version[1] = NVM_VERSION_MINOR; info->version[2] = NVM_VERSION_PATCH; - down_write(&nvm_lock); + down_write(&nvm_tgtt_lock); list_for_each_entry(tt, &nvm_tgt_types, list) { struct nvm_ioctl_info_tgt *tgt = &info->tgts[tgt_iter]; @@ -1208,7 +1208,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg) } info->tgtsize = tgt_iter; - up_write(&nvm_lock); + up_write(&nvm_tgtt_lock); if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info))) { kfree(info);