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 EB84C378838; Fri, 4 Sep 2026 06:05:33 +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=1788501935; cv=none; b=NCaHkt/t8HDQCOvmbxl+F3zoSeTmeghM0qrf8JiPzljkfgYFekUPIYKa1spZwfoA3HcV7/RjNr3TX9JRmHa81HzJd9YSmHnnZ35t8IUv1StH7X0rgtPbQOVISeLI7J6gQ+MilmIW5G4mZXPNBZNe8WZ5maCZLYnoxY7Jnuqn6mY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788501935; c=relaxed/simple; bh=fSMEnNWg40hyAySx08UPkbCobX+iMZsEksB5eujVlmY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U4/sa5tiDzOjjiv84xggj1/+yN2AUaX8swg0ph8Zx2btzgLc/hhAeZo1v7Uc4I6lWQt0NWNn645ojMLvsV26e4zeAeLSxTV6veoM3WzIj/GzzY+ED487EvF28426iKroq07ZW0HucZzTUJqJri4VEZpyA/9IqPCF6l50n5mhqdU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jfD+UzYw; 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="jfD+UzYw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A7371F00A3D; Fri, 4 Sep 2026 06:05:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788501933; bh=K4/tW7y8OpI6fT9sfxDEq1nCSdnis5swI81lfCZbJJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jfD+UzYworUYIyaoWafHQOs1hIt798ZZowspJ5AS0ZjMuolgp03XS4pUtDYT5EsRK BIBOplGx2gsNChNkfu31QFGKAZKPpb6BpJfkdmkZOFp7wKnLb3+U2GWwI9b363d4xR coJQ7D7UpRzcrN1o3c1Y3my8pPXe4ii+xBhV9y8c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Borys Tsyrulnikov , "Kiryl Shutsemau (Meta)" , Dave Hansen , Kai Huang , Kuppuswamy Sathyanarayanan , Binbin Wu , Rick Edgecombe Subject: [PATCH 6.12 030/403] x86/tdx: Fix off-by-one in port I/O handling Date: Fri, 4 Sep 2026 06:57:13 +0200 Message-ID: <20260904045735.499446770@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045734.806166532@linuxfoundation.org> References: <20260904045734.806166532@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kiryl Shutsemau (Meta) commit 0f63e656b1c679d32ac595de29d10c03efca6a25 upstream. handle_in() and handle_out() in arch/x86/coco/tdx/tdx.c use: u64 mask = GENMASK(BITS_PER_BYTE * size, 0); GENMASK(h, l) includes bit h. For size=1 (INB), this produces GENMASK(8, 0) = 0x1FF (9 bits) instead of GENMASK(7, 0) = 0xFF (8 bits). The mask is one bit too wide for all I/O sizes. Fix the mask calculation. Fixes: 03149948832a ("x86/tdx: Port I/O: Add runtime hypercalls") Reported-by: Borys Tsyrulnikov Signed-off-by: Kiryl Shutsemau (Meta) Signed-off-by: Dave Hansen Reviewed-by: Kai Huang Reviewed-by: Kuppuswamy Sathyanarayanan Reviewed-by: Binbin Wu Reviewed-by: Rick Edgecombe Link: https://lore.kernel.org/all/CAKw_Dz96rfSQc6Rn+9QBcUFHhmkK+9zu+P=bxowfZwxrATCBRg@mail.gmail.com/ Cc:stable@vger.kernel.org Link: https://patch.msgid.link/20260713133753.223947-2-kirill@shutemov.name Signed-off-by: Greg Kroah-Hartman --- arch/x86/coco/tdx/tdx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -606,7 +606,7 @@ static bool handle_in(struct pt_regs *re .r13 = PORT_READ, .r14 = port, }; - u64 mask = GENMASK(BITS_PER_BYTE * size, 0); + u64 mask = GENMASK(BITS_PER_BYTE * size - 1, 0); bool success; /* @@ -626,7 +626,7 @@ static bool handle_in(struct pt_regs *re static bool handle_out(struct pt_regs *regs, int size, int port) { - u64 mask = GENMASK(BITS_PER_BYTE * size, 0); + u64 mask = GENMASK(BITS_PER_BYTE * size - 1, 0); /* * Emulate the I/O write via hypercall. More info about ABI can be found