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 4EE4933A9E2; Sat, 12 Sep 2026 15:26:34 +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=1789226795; cv=none; b=jDa4lDUQvtKC9Nl2uNCQkZIg4QLppxxoy1olZ3bAHWfwjaSV76eWGn2oSxm0FfX52EdBnSPZDd02aFenpDjcbvIPlKlVYKyoLWvd/NnBI1+8MGEgoCZX0KXh8jFaOrw20Jf2QqqvsXkWyNjvjCKq0KesNR86uZvdDcjiBTik6cg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789226795; c=relaxed/simple; bh=ZOwEPdEi02xhz1SkZKdAa4arsMjYxGT2sXysB2sWj+Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uJ4SNU5dnbfTtzwb3nnK1FbC91toKkTKGqDPblLS5+6JSrhcaDXIUgbhwMO/ossRlU0Ta9cy+p9AIPhRjVtkgivTMJ1mIIye8t7TnjXSVRKrL3rDLdYURtaKBhbuHW4tp+w9t6ZXWhMEGhTAY0o/TqsaDXEL9mHoeS1kehEh1Ww= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tdOQqV8Z; 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="tdOQqV8Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17C5C1F00893; Sat, 12 Sep 2026 15:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789226794; bh=7Cv4pymvuCfMWf/Ol8r90w6RGAmXPB5WuniPu1Eu9UY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tdOQqV8Z3WWGFQm4CdrJeJik6A+eBK4fSF4QduHkYQFVnOJpuhzeU8MOVd71Whfiz ZhlXZ3l+Ic5lKNIpTHgZkAeNzbpHE5MwJzIIyxwe0u0TRwmUBf+J4RJB+4fPPxCHVw MqeozJ1fTLHrclxLna20Wf83pNr4v64nLee9+iwI= 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.1 0013/1191] x86/tdx: Fix off-by-one in port I/O handling Date: Sat, 12 Sep 2026 08:45:41 +0200 Message-ID: <20260912065548.406264486@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065548.086904252@linuxfoundation.org> References: <20260912065548.086904252@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.1-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 @@ -462,7 +462,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; /* @@ -482,7 +482,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