Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3029739pxb; Mon, 18 Apr 2022 13:56:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0BbRABugi3A1OtP2ydoD5kYs3KXRRsYzsqpenzLCAaLAQvl60ARBUdUFEguH/Y2voaq5B X-Received: by 2002:a05:6402:914:b0:41d:8d96:57e1 with SMTP id g20-20020a056402091400b0041d8d9657e1mr13953747edz.3.1650315401476; Mon, 18 Apr 2022 13:56:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650315401; cv=none; d=google.com; s=arc-20160816; b=AepugETBePT7ZspLSQ3LXByKmV8ivSxAc8HP9aAtAPE/5HS6zW9BwApn353ocOwOnh Md4UafQJGyX1SaeIuOlb0pzWU/XQSYSTZTVcYkrNKyy4n2qDHvGTTK7/9kECBy78cn32 agSqQ1/V7Ij/frLUc5yWnZZSb9lSElK454FwP9CeiHqdzor9tiIoaehN5SfV575BvFh5 bQD1KTkDCatYYGzaXQpVDtAO4Y3MQL5RykAp366gkqenjIMNwIyr1yiYqaq8nBc0brV4 LJPQXFK41oRy37CHDrwwD8VAF0vQTsGnqnW1Jgfz2S9c1QSzk9Yir704ETfxTYpRfBW5 /1VQ== 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=eesPopAz4LvzMwwf9lM7Oqh7ByM6FZtNomXClluYIY4=; b=whz8JclDAcJhxCn6HSaBU5zJFXuorlFAXvBWwQmlC7Iy8Xo7wRLkxwLE5SFz741h79 e9BU/ACHg6qNaA3k4J2GmdB+upAk3IfEuG93G3QIoWkqav4OiOpdjkjlj5pFwoInxZfR HLDwaBZd0jw8rmHnWGTnRxtHGmYBxYam/LoLLI64VisGfUo14DZRFzq33df3CMAOfSGX YI0Jt+45r+zTNotW8HQuerufe2aWRmfx+qFA8enbcrURZV2TJ7aouqn1GobdLnf8yZAl tf2pg/zgkrmpMpsW3YbBPgdsABBBXEhNhiS8f3jeVNKZh6f35uFxzYJNWT6/t/mj9vv6 lfBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="H/clvQQ7"; 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 l4-20020a170906938400b006e8d683e515si6414608ejx.821.2022.04.18.13.56.17; Mon, 18 Apr 2022 13:56:41 -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="H/clvQQ7"; 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 S234071AbiDRMfD (ORCPT + 99 others); Mon, 18 Apr 2022 08:35:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239584AbiDRM2e (ORCPT ); Mon, 18 Apr 2022 08:28:34 -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 60C771FCFC; Mon, 18 Apr 2022 05:22: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 E383D60F0C; Mon, 18 Apr 2022 12:22:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBCA1C385A7; Mon, 18 Apr 2022 12:22:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650284527; bh=Ac1i+RF0ABR8FrSNXf/01Y/H4o1qgHwU85zwiKBQmvw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H/clvQQ73WMn2pudcLsAvAFoLGiFr6OBStkvmp8zYO1+MnG0tvfx1a0BJRQdKqYIc HDRpfHvVO8u4zqouHgMbbPWA32ILjxD4iXznPj9gDNGdoJiwp8cy9cZIwxVq+BISWs 6TlJpwAPX96lLO3hAlJYdvZTzixsxe/TeISy41Lk= 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 5.17 145/219] scsi: target: tcmu: Fix possible page UAF Date: Mon, 18 Apr 2022 14:11:54 +0200 Message-Id: <20220418121210.948801997@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121203.462784814@linuxfoundation.org> References: <20220418121203.462784814@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 7b2a89a67cdb..06a5c4086551 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -1820,6 +1820,7 @@ static struct page *tcmu_try_get_data_page(struct tcmu_dev *udev, uint32_t dpi) mutex_lock(&udev->cmdr_lock); page = xa_load(&udev->data_pages, dpi); if (likely(page)) { + get_page(page); mutex_unlock(&udev->cmdr_lock); return page; } @@ -1876,6 +1877,7 @@ static vm_fault_t 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 dpi; @@ -1886,7 +1888,6 @@ static vm_fault_t tcmu_vma_fault(struct vm_fault *vmf) return VM_FAULT_SIGBUS; } - get_page(page); vmf->page = page; return 0; } -- 2.35.1