Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2906573pxb; Mon, 18 Apr 2022 10:45:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsDC3IZ8zCmSG+JW6Pyjm2Y510/2HFyIl49qiwMZwQ6NAGawyChBVzHKNYFgWt5Wyi1CWh X-Received: by 2002:a17:90a:550e:b0:1cd:e722:8b82 with SMTP id b14-20020a17090a550e00b001cde7228b82mr19602694pji.223.1650303915469; Mon, 18 Apr 2022 10:45:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650303915; cv=none; d=google.com; s=arc-20160816; b=0RdMsi0VS0oqsrQbRf/hlo9iuK09V/xn/8LX6pX8w4R9Njqo/QFNpn36sLVCBAWjOn VyoXHQ7aiddPpHQ9VKeCyNjtGlXu7PYzCv6p/Evj56NlByVm4zbkISzrGH4VzhMa9aBd BQQ8QBag3jGXXSL/Q5p3EkiIDD9apC0nhpp4fidWsDTnw1r3EcEjtGigFCjc93VNXZW3 dX0q0fpIef6z3I9qUEs+rIfJE81mdyHtUkbbJC1g50pDMpxoJL2caBabY2Eb2P9ezrFL Q1ZrBNMVvPwOZt1j/MYnhzklqsLEN68mC16Z9SCl9M7664lRMFgHWxKBOoWXNolTnaMW coyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qshcozxwtJHPUhojf7N+prPTkrqr4nc4OVkWf8wL/Hg=; b=AT1fJr23pGzK56dmB/myBXVgY00r/GGbsZskBXqHjWFe+mUjtAeRkCzu5C31A0C1oa ArZlXghGvkSmPEfHc9Zf/gWYX/mTXBjMCmDS2k7TQLkMA5MPNzRwE83wsXCl7kvqcI8I bvNHgtDx9XRdefX4nlfW7+RVBowtHXJ6N1ypUj4FE6PLt6mKEvklihvdS7FQlEzk92se L86kw6uMIxqJRrHMnMgbC3HJLyQjZMsGnFYWzcKaEt4izyNATjO5TrwmlksnOrUMsWi6 /CX8RAW3h/8XOOVGx8BkAL+oTxkc7B30I9bfCGNE2xde4lNtsP1w4VZ1D5aENezDiW0x 3vGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g3hVQ8SL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j17-20020a170902da9100b001584547f62esi10693687plx.256.2022.04.18.10.44.59; Mon, 18 Apr 2022 10:45:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g3hVQ8SL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240732AbiDROFN (ORCPT + 99 others); Mon, 18 Apr 2022 10:05:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241766AbiDRNrU (ORCPT ); Mon, 18 Apr 2022 09:47:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21BC92980D; Mon, 18 Apr 2022 06:01:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 983B160929; Mon, 18 Apr 2022 13:01:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89BF0C385A1; Mon, 18 Apr 2022 13:01:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286867; bh=x0vO82PgmsO84hJdKK64ihCc5vTDwaWia8Yej7d8jas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g3hVQ8SLd2EM8Gg3vbg+xZG/N/qWIG6Wft3ttX0p2sYIdwndznsEc113vA96uo+tN gzuv750cdWsCl7e59HLT5IrQa7IZFrUbzWNCZDPe7gKMpDJ852ZdzsN+lqsxkHMdXc MAGu5qwzVn+ZWOwuqa06Kj+frVAo7RE3Of2heLrQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bodo Stroesser , Xiaoguang Wang , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.14 271/284] scsi: target: tcmu: Fix possible page UAF Date: Mon, 18 Apr 2022 14:14:12 +0200 Message-Id: <20220418121220.588425893@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaoguang Wang [ Upstream commit a6968f7a367f128d120447360734344d5a3d5336 ] tcmu_try_get_data_page() looks up pages under cmdr_lock, but it does not take refcount properly and just returns page pointer. When tcmu_try_get_data_page() returns, the returned page may have been freed by tcmu_blocks_release(). We need to get_page() under cmdr_lock to avoid concurrent tcmu_blocks_release(). Link: https://lore.kernel.org/r/20220311132206.24515-1-xiaoguang.wang@linux.alibaba.com Reviewed-by: Bodo Stroesser Signed-off-by: Xiaoguang Wang Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/target/target_core_user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 96601fda47b1..f687481ccfdc 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -1165,6 +1165,7 @@ static struct page *tcmu_try_get_block_page(struct tcmu_dev *udev, uint32_t dbi) mutex_lock(&udev->cmdr_lock); page = tcmu_get_block_page(udev, dbi); if (likely(page)) { + get_page(page); mutex_unlock(&udev->cmdr_lock); return page; } @@ -1233,6 +1234,7 @@ static int tcmu_vma_fault(struct vm_fault *vmf) /* For the vmalloc()ed cmd area pages */ addr = (void *)(unsigned long)info->mem[mi].addr + offset; page = vmalloc_to_page(addr); + get_page(page); } else { uint32_t dbi; @@ -1243,7 +1245,6 @@ static int tcmu_vma_fault(struct vm_fault *vmf) return VM_FAULT_NOPAGE; } - get_page(page); vmf->page = page; return 0; } -- 2.35.1