From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B66F4FC359; Thu, 17 Sep 2026 17:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789664769; cv=none; b=VEWbSUq7Vt4fyag2ebAnnqYXHJG81tj0ziym5lqAo6pjfuUg8e7Q85iQXirACo7Ze56FOuB4sbDFcfiPdf7a1S4bS6bK3qy2ydViVftxSWcyo2k+UwffSvB3k4/TGI4d4bYfiBBK8OnmfMAOMSGf6ZBKeJUtKlhLy5KKVNrxviQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789664769; c=relaxed/simple; bh=MP9+ynBl8nTezkd0wWRrm3LUjkIdDJYwrMPS0keZxuI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kCKeaNNFBJlenhdN8Nv16yTDfRU4egrw/0PtmDUm5BwMoC62VVmSpRU8VeCqm6OwM3JBd5dyHleJ4zsr7DHu3iLp1IOIS5ZSUgfegB/hZ3XDvoZHE3j0xlXzZHguda7pUe9fKz1pBHUb7XO2PER0zliWv9fd3z5xEDS9sI7XN3k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Fhn+A/JI; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Fhn+A/JI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 578EA1F000FF; Thu, 17 Sep 2026 17:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789664767; bh=s0kNwFK5peK2NU597Bi1FZiBRFgiFE8Txp8TNHuhmMM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Fhn+A/JI0+noev96FxnBRWd/QbcWkoZo/2HmFGFs4Z62XPP3zwTmFPDogCV12Trd3 ztfpBJ+BYUunj8yxRPHBByfTpH1s+k8QaG47hRl6cUKgNaue4Wars6977RP1MM8z/r tATewiEkfczNDyiKalTgk0zIy80jW3Ifcqgu+q4k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yousef Alhouseen , Stefano Stabellini , Juergen Gross , Sasha Levin Subject: [PATCH 6.18 0483/1250] xen/front-pgdir-shbuf: free grant reference head on errors Date: Thu, 17 Sep 2026 16:04:38 +0100 Message-ID: <20260917151605.056829436@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917151551.901433442@linuxfoundation.org> References: <20260917151551.901433442@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yousef Alhouseen [ Upstream commit 678d59219ce0ae883f04c96936222c6168ef1164 ] grant_references() allocates a private grant-reference head before claiming references for the page directory and, for guest-owned buffers, the data pages. The success path frees the remaining head, but claim failures and grant_refs_for_buffer() errors return immediately. Unwind through a common exit path so the private grant-reference head is released even when granting fails part-way through setup. The caller still tears down any references already stored in buf->grefs. Signed-off-by: Yousef Alhouseen Reviewed-by: Stefano Stabellini Signed-off-by: Juergen Gross Message-ID: <20260629160517.29340-1-alhouseenyousef@gmail.com> Signed-off-by: Sasha Levin --- drivers/xen/xen-front-pgdir-shbuf.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/xen/xen-front-pgdir-shbuf.c b/drivers/xen/xen-front-pgdir-shbuf.c index 223870a0111b2..e7fb06f607711 100644 --- a/drivers/xen/xen-front-pgdir-shbuf.c +++ b/drivers/xen/xen-front-pgdir-shbuf.c @@ -447,8 +447,10 @@ static int grant_references(struct xen_front_pgdir_shbuf *buf) unsigned long frame; cur_ref = gnttab_claim_grant_reference(&priv_gref_head); - if (cur_ref < 0) - return cur_ref; + if (cur_ref < 0) { + ret = cur_ref; + goto out_free_refs; + } frame = xen_page_to_gfn(virt_to_page(buf->directory + PAGE_SIZE * i)); @@ -459,11 +461,13 @@ static int grant_references(struct xen_front_pgdir_shbuf *buf) if (buf->ops->grant_refs_for_buffer) { ret = buf->ops->grant_refs_for_buffer(buf, &priv_gref_head, j); if (ret) - return ret; + goto out_free_refs; } + ret = 0; +out_free_refs: gnttab_free_grant_references(priv_gref_head); - return 0; + return ret; } /* -- 2.53.0