From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f202.google.com (mail-oi1-f202.google.com [209.85.167.202]) (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 09AED3B42F1 for ; Mon, 15 Jun 2026 19:37:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781552264; cv=none; b=kmsjcp+Bq7RxQwaZh/Bb4Y1fjVgsQ7p+UQ81jH6vD+gDdxkr16e/D7i163JClzJzxHnaenGQe3Qirik99oxFrlBtlkIg9sgwd+rNFx6LiqvsnK/5xsi00qonjOyeFmLzPXhnllpcEA4IqrkIbidTtwSIJ4kTqpQ7Tp0IxVH5jU4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781552264; c=relaxed/simple; bh=LroGjFbOcXZkvxakXudDJ8eQsKutj0s5+zQfOiyOpbI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AbpFHAc3gaiqRLKYLOD5zMjZi3g7PxPZhZ0hvIfmZq+hK1pbPK4++kp8plpvS5QM5lsygHxKbaOglXso2jY1e+P3SM//Ny6q1NOxL64eehFppGlQNprf0ibNz6kJWDYtbupL3VuzK9QkE5BZGBkAE7aseQO8VYVKw0AE4bwieXk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--avagin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=k+W/qr7c; arc=none smtp.client-ip=209.85.167.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--avagin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="k+W/qr7c" Received: by mail-oi1-f202.google.com with SMTP id 5614622812f47-48656ba24fdso5639328b6e.2 for ; Mon, 15 Jun 2026 12:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781552255; x=1782157055; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fP4hlc+Lp5NgaEqwr+Sx0bLv+++cHMU8/Y1YWFsBPuU=; b=k+W/qr7cZ6eGlJVi6f4dgsv/H+zVZWO+JikHr8pmECVaFzebH2KadGtUFCQRO+eQjI 60sDt7iBDOXOVws93/HmpW4WPlZbYsbSwmGrZMwLnGN7kVFsyzTFRZJAMyI9yiND+ooq 7cXlYiApYPSTY4I/ksodbDWlMyA58JJzEw44eMfs+DbXY2xTgX/cP21W7/5mfmZ6Dwf3 iRW6ztkQw8oMyV0DS7QrFfeWDJvaGR2nL2kjrGoZR/tsCjUMXuTfrUjPZMw38gIRpYPi rkulPa+PqY3LecXAcMTiJ4EjJ5LXoevuDby7DkAikCiIEYGAwA/T1eqDERROYnK1rU99 cTEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781552255; x=1782157055; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fP4hlc+Lp5NgaEqwr+Sx0bLv+++cHMU8/Y1YWFsBPuU=; b=m3cuowUEYL3y76ZWjdecF3xTKkiKccdkDuj22OS/p1Itt6EvfQt9EorAURTPvCX1pf tA9FtMlHc0ERa1uPmQmN3Slie6UhRA6gSLqwrO2BjnL7jTdr6sMFuCmJY3FCilQCGIeH cA7t/EoF7rVkg0e1cPku+yTaELXYUdzjDsFEiOcOXKftkBdzqTerQ23vbN29Ge6JG+Iv SY353YUapisLeoiRxxUxfElNxEgQnVRE2E99otMBvvjRRNMmG2/FSCZX4BsQEv8RwF33 VGQmPcFtaBnEZ0hYR5I7eZSre+4qNdU9cgIVuBjqdAfY9XsOVyN1duwM5dGOfwkrYxXb jfCw== X-Gm-Message-State: AOJu0YzuXxAm+lWk8UVCqTgonvuBjNeRH38bhQvLNhcIZ9NLjED0O8S4 Zv2g9v+39sVJo0fpX3VVG+eBac3Yd5h+NVdfIRwCVNdmJ3IsWyusyl0tlfyueacW8aogN5jEiUQ 1cj3R4A== X-Received: from iohf19-n2.prod.google.com ([2002:a05:6602:a5d3:20b0:978:ad30:f0da]) (user=avagin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:1799:b0:486:3537:2199 with SMTP id 5614622812f47-4884c0ea7admr404412b6e.17.1781552254932; Mon, 15 Jun 2026 12:37:34 -0700 (PDT) Date: Mon, 15 Jun 2026 19:37:14 +0000 In-Reply-To: <20260615193716.1843340-1-avagin@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260615193716.1843340-1-avagin@google.com> X-Mailer: git-send-email 2.54.0.1189.g8c84645362-goog Message-ID: <20260615193716.1843340-9-avagin@google.com> Subject: [PATCH 08/10] selftests/x86: Add a sigframe insufficient xstate_size test From: Andrei Vagin To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "Chang S. Bae" Cc: linux-kernel@vger.kernel.org, criu@lists.linux.dev, Dave Hansen , x86@kernel.org, Andrei Vagin , "H. Peter Anvin" Content-Type: text/plain; charset="UTF-8" Extend sigframe_fpu_portability to include an insufficient xstate_size check (test_insufficient_xstate_size). Verify that the kernel correctly rejects signal frames where the xstate_size is too small for the enabled features in the xfeatures mask. Signed-off-by: Andrei Vagin --- .../selftests/x86/sigframe_fpu_portability.c | 68 +++++++++++++++++-- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/x86/sigframe_fpu_portability.c b/tools/testing/selftests/x86/sigframe_fpu_portability.c index 169548892f92..462219905303 100644 --- a/tools/testing/selftests/x86/sigframe_fpu_portability.c +++ b/tools/testing/selftests/x86/sigframe_fpu_portability.c @@ -12,19 +12,24 @@ #include #include #include +#include #include "helpers.h" #include "xstate.h" /* - * This test verifies the FPU portability of the signal frame. - * It verifies that the kernel correctly restores the xstate context even - * if the frame size has been manually reduced (shrunk), as long as the - * FP_XSTATE_MAGIC2 marker is correctly placed. + * This test verifies the FPU portability and consistency of the signal frame. + * + * - test_shrunk_xstate_size: + * Verifies that the kernel restores state from a frame with xstate_size + * shrunk to only include active features. + * + * - test_insufficient_xstate_size: + * Verifies that the kernel rejects a frame if xstate_size is too small for + * the features enabled in xfeatures. */ #define SIGFRAME_XSTATE_HDR_OFFSET 512 - #define XSTATE_SSE_ONLY_SIZE (SIGFRAME_XSTATE_HDR_OFFSET + XSAVE_HDR_SIZE) #define XFEATURE_MASK_FPSSE ((1 << XFEATURE_FP) | (1 << XFEATURE_SSE)) @@ -148,15 +153,66 @@ static void test_shrunk_xstate_size(void) clearhandler(SIGUSR1); } +static sigjmp_buf segv_jmpbuf; + +static void handle_segv(int sig, siginfo_t *si, void *ucp) +{ + siglongjmp(segv_jmpbuf, 1); +} + +static void handle_insufficient_xstate_size(int sig, siginfo_t *si, void *ucp) +{ + ucontext_t *uc = ucp; + void *fp = uc->uc_mcontext.fpregs; + struct _fpx_sw_bytes *sw = get_fpx_sw_bytes(fp); + + /* The origin frame contains an AVX state. */ + sw->xstate_size = XSTATE_SSE_ONLY_SIZE; + + *(uint32_t *)(fp + sw->xstate_size) = FP_XSTATE_MAGIC2; +} + +static void test_insufficient_xstate_size(void) +{ + uint64_t v[4] = {0, 0, 0, 0}; + + sig_err_buf[0] = 0; + sethandler(SIGUSR1, handle_insufficient_xstate_size, 0); + sethandler(SIGSEGV, handle_segv, 0); + + v[0] = 0x1111111111111111ULL; + v[1] = 0x2222222222222222ULL; + v[2] = 0x3333333333333333ULL; + v[3] = 0x4444444444444444ULL; + write_ymm0(v); + + if (sigsetjmp(segv_jmpbuf, 1) == 0) { + raise(SIGUSR1); + sig_print("Inconsistent size was NOT rejected\n"); + } + + clearhandler(SIGUSR1); + clearhandler(SIGSEGV); + + if (sig_err_buf[0]) + ksft_test_result_fail("%s\n", sig_err_buf); + else + ksft_test_result_pass("Inconsistent size correctly rejected\n"); + + clearhandler(SIGUSR1); + clearhandler(SIGSEGV); +} int main(void) { ksft_print_header(); - ksft_set_plan(1); + ksft_set_plan(2); check_avx_support(); test_shrunk_xstate_size(); + test_insufficient_xstate_size(); + ksft_finished(); return 0; } -- 2.54.0.1189.g8c84645362-goog