Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1473933lqb; Sun, 26 May 2024 02:44:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXJ7BCcnfPBojC1Ha5w+5qx1PijH24hhi4UkfTButemsQNnWsWExy0Nk1PJTFdWRbztUeK3wGCowXgwbgbJrwyetukF6dpmnYhWXhck5w== X-Google-Smtp-Source: AGHT+IFWx6i6mT0EukGdukwFn5DjjiDA9uOzf8wkvJ5pdujoF3c4kE+GmGTIvzHTJYLkBisk56OL X-Received: by 2002:a05:6358:52cf:b0:18a:9bba:972a with SMTP id e5c5f4694b2df-197e566fb82mr592523755d.32.1716716683045; Sun, 26 May 2024 02:44:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716716683; cv=pass; d=google.com; s=arc-20160816; b=fI9UtGrapQfwfWAfa3jG8Djl0AtbaMP7iZBT/ZyHx1sUprYqx34ElWtMbqdk3b5gc9 AnWXBjTB0GBD2Mt5qlMkV3WlVgm3+qvCkgw6zZ6lY/W1CR5BM1mTK7Fvlgb6cR3eJr7F zI8Y4sBhp8uAB/G/0+J10miCM6/tTv+HUKSZ2YMk/VLtLxRLpr9jSs79kzxn/KHwTx3n Md5uah8BtAuc2ERGY8V6lTc5KSOb3ZiY8NvN0vC4j07uXVzWEd7SWYxALg/2aqWIBZ/u 2Rpf7Y6t642nnq8OVbSYeT4cD8Q509PFH1/6HJdMIFOU5JDiqW152OlTyIibhM/25ssr 8+SQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UwX/8qUlFb3km3W4WeeBJ++XO3510ePxSCR57FtaRqA=; fh=OU1KUoTrn77amHFGlKoo97hx/ecw7gFpSGpGlv4wqcs=; b=OC66LM+iSO5Mvwb4Y25/eoNMpQ2fhy+DkUPsR6a0zAiE/zjBv5HzsE3VTBtxiGZh5y 2k8w5fYpn4JEAQKiUWDLrZ4v7ui74gBQzLh+AKfJe00ansgfAJ+/kSfklx2m364ovtSl BJ5sNRDp1mnAGM9cDsE9gbZaiJOZx7dqIovGAV42+ITpdnF2dnDhnqQOip9Vs/oHiN2e ay3JQQyUAmwA1SW83T/xLnXvHvt3otKhru/8pYqJPBV3Hzxd7g9JfJobUfPRSTKMwSI9 McEsn0pbocO7wAkB815LXLBfaQPYYvY53pHwN95eunYSFEtn1j1T8WbowHNKLajIpqCo 0iXQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FMMzgPDG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-189654-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189654-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-682288e6751si4359193a12.471.2024.05.26.02.44.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 02:44:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189654-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FMMzgPDG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-189654-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189654-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 6139D282027 for ; Sun, 26 May 2024 09:44:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B3452BB0E; Sun, 26 May 2024 09:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FMMzgPDG" 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 A8E642B9C5; Sun, 26 May 2024 09:42:13 +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=1716716533; cv=none; b=tE/+41o9sTwvbvt6rDNgCqN4xYgxEPBR3ym2tg7i6lMRVNeDIEk7/BhPYbdGNyGtDcxj3NOXEV16u30sKBOm0JoHZ0HvNsP7ptqNjFperpE8AKymVdBRM5Puxf0Z3Uqu8QfGmu9E/xbzxvXj1UsPi0FDgVl2dKQy9ape49Hsbow= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716716533; c=relaxed/simple; bh=Pn2wC7Qjgmx1WJ5h/NAhgXkp/LKfK1z1n1o1iNJNFAg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MwcSVQeNDOlwj2fmxePBAYVkisVugy8A0urFYqsAHtFEokJOKxbfobNKJRXxC78MGN6enTa2ElLpcISgD1bT0a21yoyqs+CfKqLwrHXHHWMt+f69bUFq7c4ahZnHRWeGYCiu2gm0RkJh0gJWPeq1wHZV8GaRW7Dx0mF3w2SOch0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FMMzgPDG; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22C7CC4AF08; Sun, 26 May 2024 09:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716716533; bh=Pn2wC7Qjgmx1WJ5h/NAhgXkp/LKfK1z1n1o1iNJNFAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FMMzgPDGEnT5yIxmjV4IECZru5Hz3SODKsp8IL6VaAbwV1dc814QtbvZl1O10YZni vMcrGjWtTOT/QzcYYfmlouMFkYS565dwlx8T8XVPqjRaolZzLQcS9EZBF/75cvlQs/ oWkFGx90X4tMeFRf8WlbZKM2VydCeINDIaPdoEVGaB30oJ9R/SE9+w+h0E1DQnR8Iy Wf+3mjV7mw9XXvmrTqU1uJre5jvRukSNBF90so6PqDPN2RBxrCMV/eKyTDTbevWHx/ 9cHSr39svICBlwP7Tweo1HFeSHad5JErqiLbT30oTC81WLaI0wisCxqHE8zW1S48p8 V2L+aSfTYj78Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , Erhard Furtner , Nathan Chancellor , Justin Stitt , Sasha Levin , kasan-dev@googlegroups.com, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH AUTOSEL 6.9 13/15] ubsan: Avoid i386 UBSAN handler crashes with Clang Date: Sun, 26 May 2024 05:41:45 -0400 Message-ID: <20240526094152.3412316-13-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240526094152.3412316-1-sashal@kernel.org> References: <20240526094152.3412316-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.9.1 Content-Transfer-Encoding: 8bit From: Kees Cook [ Upstream commit 2e431b23a13ce4459cf484c8f0b3218c7048b515 ] When generating Runtime Calls, Clang doesn't respect the -mregparm=3 option used on i386. Hopefully this will be fixed correctly in Clang 19: https://github.com/llvm/llvm-project/pull/89707 but we need to fix this for earlier Clang versions today. Force the calling convention to use non-register arguments. Reported-by: Erhard Furtner Closes: https://github.com/KSPP/linux/issues/350 Link: https://lore.kernel.org/r/20240424224026.it.216-kees@kernel.org Acked-by: Nathan Chancellor Acked-by: Justin Stitt Signed-off-by: Kees Cook Signed-off-by: Sasha Levin --- lib/ubsan.h | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/lib/ubsan.h b/lib/ubsan.h index 0abbbac8700d1..0982578fbd98f 100644 --- a/lib/ubsan.h +++ b/lib/ubsan.h @@ -124,19 +124,32 @@ typedef s64 s_max; typedef u64 u_max; #endif -void __ubsan_handle_add_overflow(void *data, void *lhs, void *rhs); -void __ubsan_handle_sub_overflow(void *data, void *lhs, void *rhs); -void __ubsan_handle_mul_overflow(void *data, void *lhs, void *rhs); -void __ubsan_handle_negate_overflow(void *_data, void *old_val); -void __ubsan_handle_divrem_overflow(void *_data, void *lhs, void *rhs); -void __ubsan_handle_type_mismatch(struct type_mismatch_data *data, void *ptr); -void __ubsan_handle_type_mismatch_v1(void *_data, void *ptr); -void __ubsan_handle_out_of_bounds(void *_data, void *index); -void __ubsan_handle_shift_out_of_bounds(void *_data, void *lhs, void *rhs); -void __ubsan_handle_builtin_unreachable(void *_data); -void __ubsan_handle_load_invalid_value(void *_data, void *val); -void __ubsan_handle_alignment_assumption(void *_data, unsigned long ptr, - unsigned long align, - unsigned long offset); +/* + * When generating Runtime Calls, Clang doesn't respect the -mregparm=3 + * option used on i386: https://github.com/llvm/llvm-project/issues/89670 + * Fix this for earlier Clang versions by forcing the calling convention + * to use non-register arguments. + */ +#if defined(CONFIG_X86_32) && \ + defined(CONFIG_CC_IS_CLANG) && CONFIG_CLANG_VERSION < 190000 +# define ubsan_linkage asmlinkage +#else +# define ubsan_linkage +#endif + +void ubsan_linkage __ubsan_handle_add_overflow(void *data, void *lhs, void *rhs); +void ubsan_linkage __ubsan_handle_sub_overflow(void *data, void *lhs, void *rhs); +void ubsan_linkage __ubsan_handle_mul_overflow(void *data, void *lhs, void *rhs); +void ubsan_linkage __ubsan_handle_negate_overflow(void *_data, void *old_val); +void ubsan_linkage __ubsan_handle_divrem_overflow(void *_data, void *lhs, void *rhs); +void ubsan_linkage __ubsan_handle_type_mismatch(struct type_mismatch_data *data, void *ptr); +void ubsan_linkage __ubsan_handle_type_mismatch_v1(void *_data, void *ptr); +void ubsan_linkage __ubsan_handle_out_of_bounds(void *_data, void *index); +void ubsan_linkage __ubsan_handle_shift_out_of_bounds(void *_data, void *lhs, void *rhs); +void ubsan_linkage __ubsan_handle_builtin_unreachable(void *_data); +void ubsan_linkage __ubsan_handle_load_invalid_value(void *_data, void *val); +void ubsan_linkage __ubsan_handle_alignment_assumption(void *_data, unsigned long ptr, + unsigned long align, + unsigned long offset); #endif -- 2.43.0