Received: by 2002:ab2:715a:0:b0:1fd:c064:50c with SMTP id l26csp98039lqm; Mon, 10 Jun 2024 14:04:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXG3F/UnKvVnTeahX8FhUY29BTuI2ckoOGMQgb+zosF7oqZVTyr6+pzLkCBQiQMIHe5zSCrJDza1CVnIkYyo4/OTkBCo5oy76vri5Eqzw== X-Google-Smtp-Source: AGHT+IHTOnrbPzinN+oRTiZtvDWEaSNF5nqJpQ32ogR4FG1xpqty0XP87LAnJ42L7U9Qom1gDsI4 X-Received: by 2002:a92:c241:0:b0:375:ab6a:f701 with SMTP id e9e14a558f8ab-375ab6afac1mr29138675ab.5.1718053480828; Mon, 10 Jun 2024 14:04:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718053480; cv=pass; d=google.com; s=arc-20160816; b=IK94eHrueEpTIkSJJOOIgh+Ato1C/x/M7M/QaDzOcDZ50JrZWWIwxfmlDFUX8y02vA l7hXA9U2fWiXWPC/9zyr9UWJ71Wy9mXfMt2l6sk28kHBd7XlJzdut7P9tcliUuXevmNt ybgF9h4qFUyoEIHFG6eVtrg25RgqMHY6y0XV3Niu4rcnJvdZmQ7N0o1ALgJvit3b28TN G9x1k15FvQWkix7z+FkpVlpeD8wb3DFceehFdfSUbyAY1DKmV7YCconer9z0DjBbSiCQ 7Tvt0EqFRwYD/mdqWQYOfbxkd9M2pAuR1BMFMVk6qV9rwSUnI4D7XNzTJqOTV6bql2dk hZDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=M86SXrcqJgdumR+PKUWjiVCuA+Iceb8MzzCMph6wsVw=; fh=dDSmDsSuILg9Xfil/btwc9/JBX7Iy+Mu13x8hiPhiwg=; b=f1gEBkyfiGRq3sgWYgAgv2bp7WGNR2KAUWF+fWBoxXPlOpijpN0RwJK8neDe4KTl7c mxPYNFyucFNnFaoEdFWHLI6T/ndOs9TuGFMya/NC7C6sIu1QoufAMB1h7FYvH/xhye1r 6+wsHVh5Jvk1usVBIXnWa7NcClyL3EVm8+SbEpdnCm2XxwyOzkZnxzCUUCXgYL0wOOQQ Y91P0wDZ13OTZkIm9XIvF22nMT5AeDAfz3jkSrL78gAN9LHSlOVUsF+xpGiUfFY5PbJX HRs7w62ZspWC2RLUBOR53u9J1PpFjD6vWbSPojcF7iEazEDdGvBKREcseEXZJwtS/OKn 8AYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n4ZBRl2c; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-208900-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208900-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e439d12d36si4272282a12.874.2024.06.10.14.04.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 14:04:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208900-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n4ZBRl2c; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-208900-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208900-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 00522283BCA for ; Mon, 10 Jun 2024 21:02:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EAA5D4DA09; Mon, 10 Jun 2024 21:02:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="n4ZBRl2c" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 122615588B; Mon, 10 Jun 2024 21:02:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718053349; cv=none; b=or92NXRMPtLA5g5tVDUaLE5eH7tvNW9gMGzjG7WPQcqZ9Jf3pjAcHCYDN1iUKVHf+hJtW1xX/+fNbeNDZWt+ujllk2Nat/diuR8rRdA94ip7pGT22on0OCA4CqdYFG2tr7A5lvd6XeAEhmOWAwiqusqNzEsBM4xK+JKoYG/dvjU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718053349; c=relaxed/simple; bh=I16quwF1+onTsrxMVkn0fm482Ug44s2XCPxSOXPFib4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=YY4jVG+l0a9MoQ6Nl+tzG+A60rAvFNgxnvOrzAY4+LseIeDTQwMUpddWulf0AI/wYCgJ4qlESlf3P6XAkB9P8lbjGvQTy3a787CLQXFVM/VI/fcbZ7mUQBdJVYi4bEOotxK5lJJYh7ES2133t+5IhFqBFS/G1qc8d8zSve3jONI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n4ZBRl2c; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F0CEC2BBFC; Mon, 10 Jun 2024 21:02:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718053348; bh=I16quwF1+onTsrxMVkn0fm482Ug44s2XCPxSOXPFib4=; h=From:To:Cc:Subject:Date:From; b=n4ZBRl2cyXlJSIkF3gDY19EtyTFwwr9B5osJdmU/DHn4zYiwMscYm0B1Hr8ixIWnG zd6+RbTbOT6W73b9T7mDPCXomSwptsEvihyMxduGJwQ/uO+I5z+1mWth47qP4ThrjI asYfBHTCCwfcpaOXGQUhuXMPuPkcMscXDrG1kE90V2tPq1mmsF5EzE2WK0oxVdxLu5 qFng2XpMQuJMEQPSNvUShN+eyf9hmSv6hKP1Lq1+XyiRGidkJmQl16Ipf1xUB8ftPT I1tpPeFayNRkqSdaDJuoJfiyiZfIeXb1fxNiEn20TQ2SbOxFIpJcM+LHA45OvlTUFv +HUtoakhlBjJg== From: Kees Cook To: Thomas Gleixner Cc: Kees Cook , David Gow , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Sean Christopherson , Peter Zijlstra , Arnd Bergmann , "Kirill A. Shutemov" , Qiuxu Zhuo , Nadav Amit , Masahiro Yamada , Christian Brauner , David Howells , Uros Bizjak , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] x86/uaccess: Fix missed zeroing of ia32 u64 get_user() range checking Date: Mon, 10 Jun 2024 14:02:27 -0700 Message-Id: <20240610210213.work.143-kees@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3063; i=kees@kernel.org; h=from:subject:message-id; bh=I16quwF1+onTsrxMVkn0fm482Ug44s2XCPxSOXPFib4=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBmZ2nipwFiKWgGXL878DrUseiyOhJ2Ao6EyQM8T 7VpfqH0JIiJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZmdp4gAKCRCJcvTf3G3A JkdMD/9hflgzdc0oXm2RKx/VwC9hgxSeI6zZKTCowRa5jYMzRQZWsyIB8Id6E9+Gqw6D5mF6HFq 96U4BJuw0yRhUqGY0OoA208ntVa4+V7/XiUyAGKwzeJlPdXi0Cm3yt/g4eRa4MAt/l7kmqDdWzu Xbq6J7Aa3lbMRp8iwVnUFySxICY7bZcTN6teAPVLrnzXFehQ/whEQBH7ajNbvCurobEc56ccQhm VS66uypQJui+rSaIvRClE0vU7oYajQhBQI+pxRTiKT9uNSNR5dIUoRvRx576MATVo205PPgAqnt AAsF6glC4qBmC/by4+K8lUbXV0mFtqLBeDKZeY8rtQsvBeHbZdl+3ETq8SdKQEEvWQwITRw9/B6 +HPdPyfh6KmJlrtIbY/xtNXleh02Hic5TnRcS+2RkOYr/IusZ1HWrCswW9HaeDqMRFzb4RxwijT uMKxaLzYjO0c/f/B94WKsUTHvhrEePfllv0IH6g79pUMxmiB7Jci6+Q2yxFY6dCZXDr77XT/QWX f017TxJ/YBAG2sO23NbfUTqGMTC+QEas4EVENCkyP6oW/Zn+oA2lrdzJXvTdvE4t2nMeVehPmAn /ZgGdI+iQSw1mnbsQEQ/ULN0vuo6MCpKPLl5r3ya7ZgDiYobtE0n5W8zC+QkMk5ugYopXo3wrDu 2+ezuQl3TBbfL Hg== X-Developer-Key: i=kees@kernel.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit When reworking the range checking for get_user(), the get_user_8() case on 32-bit wasn't zeroing the high register. (The jump to bad_get_user_8 was accidentally dropped.) Restore the correct error handling destination (and rename the jump to using the expected ".L" prefix). While here, switch to using a named argument ("size") for the call template ("%c4" to "%c[size]") as already used in the other call templates in this file. Found after moving the usercopy selftests to KUnit: # usercopy_test_invalid: EXPECTATION FAILED at lib/usercopy_kunit.c:278 Expected val_u64 == 0, but val_u64 == -60129542144 (0xfffffff200000000) Reported-by: David Gow Closes: https://lore.kernel.org/all/CABVgOSn=tb=Lj9SxHuT4_9MTjjKVxsq-ikdXC4kGHO4CfKVmGQ@mail.gmail.com Fixes: b19b74bc99b1 ("x86/mm: Rework address range check in get_user() and put_user()") Signed-off-by: Kees Cook --- Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Cc: "H. Peter Anvin" Cc: Sean Christopherson Cc: Peter Zijlstra Cc: Arnd Bergmann Cc: "Kirill A. Shutemov" Cc: Qiuxu Zhuo Cc: Nadav Amit Cc: Masahiro Yamada --- arch/x86/include/asm/uaccess.h | 4 ++-- arch/x86/lib/getuser.S | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index 0f9bab92a43d..3a7755c1a441 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -78,10 +78,10 @@ extern int __get_user_bad(void); int __ret_gu; \ register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \ __chk_user_ptr(ptr); \ - asm volatile("call __" #fn "_%c4" \ + asm volatile("call __" #fn "_%c[size]" \ : "=a" (__ret_gu), "=r" (__val_gu), \ ASM_CALL_CONSTRAINT \ - : "0" (ptr), "i" (sizeof(*(ptr)))); \ + : "0" (ptr), [size] "i" (sizeof(*(ptr)))); \ instrument_get_user(__val_gu); \ (x) = (__force __typeof__(*(ptr))) __val_gu; \ __builtin_expect(__ret_gu, 0); \ diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S index 10d5ed8b5990..a1cb3a4e6742 100644 --- a/arch/x86/lib/getuser.S +++ b/arch/x86/lib/getuser.S @@ -44,7 +44,11 @@ or %rdx, %rax .else cmp $TASK_SIZE_MAX-\size+1, %eax +.if \size != 8 jae .Lbad_get_user +.else + jae .Lbad_get_user_8 +.endif sbb %edx, %edx /* array_index_mask_nospec() */ and %edx, %eax .endif @@ -154,7 +158,7 @@ SYM_CODE_END(__get_user_handle_exception) #ifdef CONFIG_X86_32 SYM_CODE_START_LOCAL(__get_user_8_handle_exception) ASM_CLAC -bad_get_user_8: +.Lbad_get_user_8: xor %edx,%edx xor %ecx,%ecx mov $(-EFAULT),%_ASM_AX -- 2.34.1