Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3546952pxj; Mon, 24 May 2021 09:06:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyc8pDbJXd9eO4OnNy72vO78hXnroCFymNYJ4brhYSyjTdHcxyYSR5Q2Vw7hFu1QSV+NQ/4 X-Received: by 2002:a6b:7948:: with SMTP id j8mr1460128iop.32.1621872386582; Mon, 24 May 2021 09:06:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621872386; cv=none; d=google.com; s=arc-20160816; b=YyjaC9RM7EO5+fG5VJf1E8AJWgO7Is/oUnQzST8LzKIHpbPEcZkECV0OV1QXVOjVHT 6FiJxF4gBXhxN+NmarZG1cdRye4nagGx7elJH3QYPJbWNHVTCwThlkN641b4lrpyzDSv 5yG4OvN//urB1R7lCJvNzSF6C1LsIDdTBdFZrD6uVdpgD2pgcuG1nB+vSGTIvv1QrdI1 5WINTYXvfm1zbH8j5AH4V+MNIpTFY3NxSWTpajwkaj2BWMLTigUqfNR+wMUmRJem+HwM QyLdJ7mHXQio5xYd2SkiLsMz6CaqJaYlPYjoQJXSRvGBWDqmoau484oDGsAvUva9/YyE CSog== 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=bZyRyMGFY6O8YsvfTmO3AcPLZTiz5UFuf0vTE5ecSgw=; b=YDRVbgZFeYnMzM80NJqEYkeeacRqIdJ68OBHFWwhXyJPNoWqJMLd31O5oI5bZyWHOx IkA9oyKJkWwUCv1dPpXp4U0dU6G6NybDqK8ZltI+4ApVSZdvdEI2VHw+PNtqE9CJlagx 0t6gVEt+2tFaJXNsrBaY/qEcT5kaga8jHEgwKPSo9enPd6zXbhbbyrcEqOFiFrWOUxny xN4bh2SjK7hE4btzTrfMoE1UO3wMDX4T0Sc4a3j7CICcKTo1fmyAJ2TUso4ygGBT3EyE QNnOtOEHPDW4g6HB89OBJzIePraqO8b4+zQ/tvnCiGwGU+acpos65Zty5/LqFnrutdOn 8vKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jrUFbH4p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a5si14587895ilh.94.2021.05.24.09.06.06; Mon, 24 May 2021 09:06:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jrUFbH4p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S236917AbhEXQEo (ORCPT + 99 others); Mon, 24 May 2021 12:04:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:40490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234644AbhEXP6L (ORCPT ); Mon, 24 May 2021 11:58:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 191A36195B; Mon, 24 May 2021 15:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621871046; bh=nb5gPHQ0lc71Pv8hxVx6JmpASmurqXzUg7X9LXFRH3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jrUFbH4pfx6eO8PIxAZSeAESaV/PP4oRu14hmh98RPir2OStr5llSFrErFj30bjN+ R/s4JiCtL1zPNkUO+lndtzrGgSDBhgpvCjmJ0UGPPh8DjWkMAqRX7B2Nma5hOJOIT6 XbvuHQ18R/otvPjR4sXKguiD218MyRhZzobogOAE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lv Yunlong , Oded Gabbay , Sasha Levin Subject: [PATCH 5.12 004/127] habanalabs/gaudi: Fix a potential use after free in gaudi_memset_device_memory Date: Mon, 24 May 2021 17:25:21 +0200 Message-Id: <20210524152335.006868701@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152334.857620285@linuxfoundation.org> References: <20210524152334.857620285@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lv Yunlong [ Upstream commit 115726c5d312b462c9d9931ea42becdfa838a076 ] Our code analyzer reported a uaf. In gaudi_memset_device_memory, cb is get via hl_cb_kernel_create() with 2 refcount. If hl_cs_allocate_job() failed, the execution runs into release_cb branch. One ref of cb is dropped by hl_cb_put(cb) and could be freed if other thread also drops one ref. Then cb is used by cb->id later, which is a potential uaf. My patch add a variable 'id' to accept the value of cb->id before the hl_cb_put(cb) is called, to avoid the potential uaf. Fixes: 423815bf02e25 ("habanalabs/gaudi: remove PCI access to SM block") Signed-off-by: Lv Yunlong Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay Signed-off-by: Sasha Levin --- drivers/misc/habanalabs/gaudi/gaudi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/misc/habanalabs/gaudi/gaudi.c b/drivers/misc/habanalabs/gaudi/gaudi.c index 9152242778f5..ecdedd87f8cc 100644 --- a/drivers/misc/habanalabs/gaudi/gaudi.c +++ b/drivers/misc/habanalabs/gaudi/gaudi.c @@ -5546,6 +5546,7 @@ static int gaudi_memset_device_memory(struct hl_device *hdev, u64 addr, struct hl_cs_job *job; u32 cb_size, ctl, err_cause; struct hl_cb *cb; + u64 id; int rc; cb = hl_cb_kernel_create(hdev, PAGE_SIZE, false); @@ -5612,8 +5613,9 @@ static int gaudi_memset_device_memory(struct hl_device *hdev, u64 addr, } release_cb: + id = cb->id; hl_cb_put(cb); - hl_cb_destroy(hdev, &hdev->kernel_cb_mgr, cb->id << PAGE_SHIFT); + hl_cb_destroy(hdev, &hdev->kernel_cb_mgr, id << PAGE_SHIFT); return rc; } -- 2.30.2