Received: by 2002:a05:7208:1509:b0:82:bbfa:f723 with SMTP id o9csp525900rbf; Wed, 24 Apr 2024 09:58:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV4G+4iEVhpjZ4x6BfIwlnQptiyJX2bPOe9YCwuljwOmY0+VM25TRhIoVcWJ+7YRV1CohPyQv6rzj5hgalgRX4I+3bYsvs79OmrCFKn2w== X-Google-Smtp-Source: AGHT+IHGyZbc7i545lhn3gALH/8kitnIpe9rly29oog80oGOveNYFfteICyEwN2K3KPiQmlTId9l X-Received: by 2002:a9d:77d4:0:b0:6eb:b266:a2a1 with SMTP id w20-20020a9d77d4000000b006ebb266a2a1mr3768801otl.19.1713977924919; Wed, 24 Apr 2024 09:58:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713977924; cv=pass; d=google.com; s=arc-20160816; b=kGUpahPuoDptJb97RQfQYeISl0Sspq/wts8w6DJf58YkYilJ5QPSos0vx2RWWBH8xy 7dhP/jBaho5HsSXwcTWBHOMGsvgXLojN0zRZDLAcqw1lOVWS+0Y4QgRaf7WnWX+/1IHu UqSqJuhck2ptYbDiO1wmdBsHb/Yy4MbaIdGTRcfJUAXZwl78QPp1t/W04nlP5ya5Pkt+ rrbNe/+If2skyyh8do8J72r8Ph09Gra8OK8ct2rh7wcITeZFhLUYkWdCi7noCsWJqbfQ I/zxXG6RKuRv16+hpKn9wVJsPmcTnrDunirvjuDGJtQK463QIul3ougHFefg0ylBstTy xOIw== 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=b+9qworkCYA/dEd2E6NqOCyfCT0RGwXnd8JnfZdAXT8=; fh=iSdvAcwHoEtwVJPd7JzjacUoUUUGUnsOHcE/F9zvzrs=; b=bhibc+HsSelIG8GNrXqFTsMC/aZBwStU+Wl86JER2gMcctvBB30QOsHXSNbUpOSl1W KfR9bVSop9yZoHSuTdKi25lSilDimMj3tHExeA0Nsmz6iLEj3L5eQUWTg+Y1vbXiQ/n8 +f9AcASy5c5z5VJFbyDTcUUR1cQjFyUCJgdnD2rbfYzH+QhAnN1NKYhejrLm6zxSw/2g 8WhXMD9AV5MOl0mJvGVL/ZInoA9iReIX4OvSOSoNiAFhQteRdEw09s2nD7HB4DhD18bz shnedQgp9P8hFuXRxz/s7QJPtJKdOISiVj8IygnOdMk7zfdP21hzOcxfv/0YQFayqVt9 mi1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="A+dLW/1n"; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-157323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157323-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id bw15-20020a056a02048f00b005ffd7f200afsi5913207pgb.357.2024.04.24.09.58.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 09:58:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="A+dLW/1n"; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-157323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157323-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id CBF5FB275B8 for ; Wed, 24 Apr 2024 16:29:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED7E41635D1; Wed, 24 Apr 2024 16:29:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="A+dLW/1n" Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2640A16190B for ; Wed, 24 Apr 2024 16:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713976188; cv=none; b=FZLAf8ryGSzy1dFAqoY6xpPlvTcj0rsBG96f525XSTw3Ha12z2wCeWAkgmmXil88H7nzAQyLfiqlTb13k5wt4Y3f2kNGfzbuJr40HhpQjn50hH5mm73fE/ejF7DJYEjThdJs5U8OXFPnPNOPQijD51Y0BJMit8OGyvm/f3U4siI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713976188; c=relaxed/simple; bh=8+7ximJNE3huew93u7w7rKw7nI9gr+b5vuxXFU9vyvI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=j0Rp+OEYgEMowIuxCjkkx5Dncx1UjPjTat9Vo/23UjLHH7oGufO+O67iFnipGWGczPBZ+bahHh0CEfOz2iFc1TrFQdEf0UXt/ndKePDIf/RrrfRfTU/LLxWohxMvRIOFt84LJ+npmi3atlD4GsbAJrti+7vj0jlkKkQHPqrXuYE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=A+dLW/1n; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2ab1ddfded1so91791a91.1 for ; Wed, 24 Apr 2024 09:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713976185; x=1714580985; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=b+9qworkCYA/dEd2E6NqOCyfCT0RGwXnd8JnfZdAXT8=; b=A+dLW/1nuw3sXHG7tlRFKZsrOJJQTLeroSS5BwbJTNp2IIxFlFuTIdUc5C+MkKV7Tq VVUKXa/s9bFwwgIOZsy6ZwsyqwkkctPuEN7S3T05Q0xTfwy8si0YvPPSRX9Sx0K5J8Vd 2zUeHYKPpCxeAL8/5+zuixDKVfO4+L2Sl1a4o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713976185; x=1714580985; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=b+9qworkCYA/dEd2E6NqOCyfCT0RGwXnd8JnfZdAXT8=; b=nqWBNUJAWP3Qri5qB2v7tYSTPdj086VnfcJpOF3qCab1Kt/ewfEgzG8hdp7BHnsizO lAtaaGQkGsq3jqUAn+YKJYy4K4r1BK/19g5CDo8cM8zkF6ay7xVfDcJqO6L3SZftCdzK XNBZB8YbEwVhMl2Pt9+gm77QTURN2xmL65hzHPrcsFWrJlxsCpp4qpwQMrTH/hecbfx7 3kOI2KVRo1r03yDTUCo4cEnBhhCmEl+whCCzdnT4ZlQ1x3OCoMA0AEG17jgkw8SNt/Lw Vor8JvoXXQcnMesf5wTvikUXuXWFzLu1HKhHb/DyrKWi29TLnM5Io11J5maXaqJy0FSU Ss6A== X-Forwarded-Encrypted: i=1; AJvYcCVgA4znJYT58SHsLyFtjoiV8THSqmionEGmehs/hak0XZ7Fu6OdZ1sdVkpYFhp8ZVVP35oydV9Jfxl+9MFSY1txoFAie3GjsRZgSAMk X-Gm-Message-State: AOJu0YxzfmhBKuufxA/mcWmCn0KEbtS8+St77TYPk2xvbnNd7bINRLGd 4YpMXMDAvfso1b5NJGm92imXxuldu3EiWEoeZmKGUjbl5dYLyVXopU8xJzaQSw== X-Received: by 2002:a17:90b:1b51:b0:2a5:12dc:1609 with SMTP id nv17-20020a17090b1b5100b002a512dc1609mr2715263pjb.39.1713976185447; Wed, 24 Apr 2024 09:29:45 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id e5-20020a17090a4a0500b002a269828bb8sm11388846pjh.40.2024.04.24.09.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 09:29:44 -0700 (PDT) From: Kees Cook To: Marco Elver Cc: Kees Cook , Andrey Konovalov , Andrey Ryabinin , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , llvm@lists.linux.dev, kasan-dev@googlegroups.com, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ubsan: Avoid i386 UBSAN handler crashes with Clang Date: Wed, 24 Apr 2024 09:29:43 -0700 Message-Id: <20240424162942.work.341-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=3634; i=keescook@chromium.org; h=from:subject:message-id; bh=8+7ximJNE3huew93u7w7rKw7nI9gr+b5vuxXFU9vyvI=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBmKTN3dyNIMp+O7q+bYM3wOmd9O8k5WMCGmgktL WF4UQsY51yJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZikzdwAKCRCJcvTf3G3A JosuD/4l0IQyly+v15MjXYIsDPKX4IUkiRHY6oGlP49ZY8fFeuSdWJ3yArBs2w2o0pI0Xz7TeNc xcw5Xe5jnSvWWVDiu6qp0yW4tCOvqM6yNZrf7rn7xlvHjmJ30bKKPw5RC0sNlkxt5V/nPLVUoER /k68qektDitJ9fBrTUwESO45p5eEMf02JAGnZEWFiKRx1VLYS9p4eLuHsegE2iV6NBeoQoWbjwp ogvJwyBtZbApgP1wO3TnY6fU2f7t91bS2KKqv7oaFXxiR1VIoHLnSjMD7E3juz/7XvDWRkdH9aV MKVZIOoiX6ab+ck7wlBvhVEUqJwGboQ9DeZ75AY2+SueBm/5ZfdIL9JRYMoCtSbMxPi+QLCfc9Z gSNMRitoL7+KpQFNircO1i/MsOr1So2bnjiGk+JJv/I9QbAI22XZRCVwFebXoc98lAhooaByiYV m+BDlmdQC9F8Bo5Qu7GUHHYcBQvrhI61ZNlcRSC2RpmDi2/grWEZCJws+Mn558xoHd9PLeX0sQK l7hQO4NRBwXVkglPNiVSiT6b/ZKBR7+ys46WMhRmOtxhm0JQhJGo5LSfrCa3HRahV8uw335O4P4 uyRt7a8PDmyCLIOM97cCwO8uPgqPud0XMPyhHaEpnusRbh5Icubm3EELeU/K+gvYCId554loEZ6 /UXvy36 I133L96A== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit 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: ernsteiswuerfel Closes: https://github.com/KSPP/linux/issues/350 Signed-off-by: Kees Cook --- Cc: Marco Elver Cc: Andrey Konovalov Cc: Andrey Ryabinin Cc: Nathan Chancellor Cc: Nick Desaulniers Cc: Bill Wendling Cc: Justin Stitt Cc: llvm@lists.linux.dev Cc: kasan-dev@googlegroups.com Cc: linux-hardening@vger.kernel.org --- lib/ubsan.h | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/lib/ubsan.h b/lib/ubsan.h index 50ef50811b7c..978828f6099d 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. 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. + */ +#if defined(__clang__) && defined(CONFIG_X86_32) +# 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.34.1