From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by sourceware.org (Postfix) with ESMTPS id 5285E3858D33 for ; Tue, 26 Mar 2024 03:34:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5285E3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5285E3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711424054; cv=none; b=d6bJhczL4jB/8NkyLnH5jAM/QUV209xAOAoGB0stdqsAiyOCJ+5AWoTJSQd1b6ilEtnNXxIW1C5d5AkW85ADevz0bdD5pxtBCPA65mKn8PDzwYv4kNGZrmdjTphHd05lmR+XqSVETNSY6xg6a8w5QIxhshSZdmkti09DkXPB71E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711424054; c=relaxed/simple; bh=nEzZA5kc6rLAyYgF4/s6zlk7C4KNVFBVhVoNkl2ZELs=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=DywSc86ltXB075FtYBEB48r38IraubGm5FMRhxPdWdSCsJWdZFfn0JVXNoS/2qP72BFbvH3q5tu+Vx2CGALVWxN+tixGemvy9RTFCgRkyl0uTqlnMY9IqZtWGF1E6WjbWTzAtW7CPehpPAcK5zf1fp/EcIznSIKaV9gkK61sVrc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-696609f5cf2so26883276d6.3 for ; Mon, 25 Mar 2024 20:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711424052; x=1712028852; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=MxEwQvPwog1+gd7QqDs6xN3SC/KYl+0rhuI6GMbTwO8=; b=EVFRoKTBMz08MTbDW01Ir8LkgwpRR8M75viIwX6wiMAGQCl2CSZxwBf+fEr/gijpGw kY0+Fh59mUR2lauVWMg1zgpROrfXpkxYnBTK9BI8QGg4shjF/ePl5VAWnwvgNRFKGASp U8DEw4stJDIAosxLLjYo5a/RYfSqWF9Wwf+2IvJgR3i0OyXgmepRz5VN/45vCGCw+pr+ 71eU1zPwV0Igg2uTluHdHMRcOP5w/9SUI6iIpX0pMWgT5JTiqMSfwmUbC4tywEYZgzcD wWJZ9OrGjJQ6x2chuNy/9mrU8sTElN4sqWobUFR2H+FdX8imS1SuvpValOXokuLcGViC WQNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711424052; x=1712028852; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MxEwQvPwog1+gd7QqDs6xN3SC/KYl+0rhuI6GMbTwO8=; b=Nyizq6/uM+FQbkc3UwHk+4RuxXtexkG08oydk2ZEJv0NX7jWWe+3cXEZZQn25ujr12 Y8PjCyg8s7TPfnaq5NZAeCo7RT3pSH+zYmCiceIynw8MfIropFyGCfLQpHlpPSPoLW74 43o8+M7ZL4oUJq/Hw236EaQPKoJ5toBhEX/YpYRZT+JR8P3v6S00iX9vafPHmyYBd3qv AfUQMWqdDRTDdyTwUWEF7gs8h5wawiUIYhkLCAWyJ0jC4e/vZ1lK/aaszcYHbmCRmLlP IYTliGJaxOMhmegW1jWlSXDet794+jSiEFzaqaneiUrXK3D33HS1jBXXCrLd+fzh0POT 9dAA== X-Forwarded-Encrypted: i=1; AJvYcCWx4dNRFYHocu4kxuk6vDrltvmuIKfJquoVJ3BcODqkajrlyMF03/++U3UuMstTJge7EBmLzizORFQAZJxAmXlpBSIIhMiWCw== X-Gm-Message-State: AOJu0Yzc5nqlHfk31yBXBA2Q7eZMUD0gIHGfEpd5M5CpTW6FyS6cOAW/ QmVDnqpi1guJQudVMxPm+G2aWILBLD5PCqGdN5qhn7UFxYw6Ew65rUxhsZNd+5lcyre1RM/cvJZ 8p6Mr0XnZS5XfmOtVfV/RuLjVfyM= X-Google-Smtp-Source: AGHT+IGpd4nFt3Gkwzm+S3/Og9G/RGUQ1bb4C/E2OO0XvjwCg4xQdBBOdEtoSzhwQSS9nASkM302Vf2bz7JKs8ukx/M= X-Received: by 2002:a05:6214:d4a:b0:696:44be:6327 with SMTP id 10-20020a0562140d4a00b0069644be6327mr6781qvr.24.1711424051694; Mon, 25 Mar 2024 20:34:11 -0700 (PDT) MIME-Version: 1.0 References: <20240312115759.4067084-1-hongtao.liu@intel.com> In-Reply-To: From: Hongtao Liu Date: Tue, 26 Mar 2024 11:34:00 +0800 Message-ID: Subject: Re: [PATCH] sanitizer: [PR110027] Align asan_vec[0] to MAX (alignb, ASAN_RED_ZONE_SIZE) To: Jakub Jelinek Cc: liuhongt , gcc-patches@gcc.gnu.org, hjl.tools@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Mar 26, 2024 at 11:26=E2=80=AFAM Hongtao Liu w= rote: > > On Mon, Mar 25, 2024 at 8:51=E2=80=AFPM Jakub Jelinek = wrote: > > > > On Tue, Mar 12, 2024 at 07:57:59PM +0800, liuhongt wrote: > > > if alignb > ASAN_RED_ZONE_SIZE and offset[0] is not multiple of > > > alignb. (base_align_bias - base_offset) may not aligned to alignb, an= d > > > caused segement fault. > > > > > > Bootstrapped and regtested on x86_64-linux-gnu{-m32,}. > > > Ok for trunk and backport to GCC13? > > > > > > gcc/ChangeLog: > > > > > > PR sanitizer/110027 > > > * cfgexpand.cc (expand_stack_vars): Align frame offset to > > > MAX (alignb, ASAN_RED_ZONE_SIZE). > > > > > > gcc/testsuite/ChangeLog: > > > > > > * g++.dg/asan/pr110027.C: New test. > > > --- > > > gcc/cfgexpand.cc | 2 +- > > > gcc/testsuite/g++.dg/asan/pr110027.C | 20 ++++++++++++++++++++ > > > 2 files changed, 21 insertions(+), 1 deletion(-) > > > create mode 100644 gcc/testsuite/g++.dg/asan/pr110027.C > > > > > > diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc > > > index 0de299c62e3..92062378d8e 100644 > > > --- a/gcc/cfgexpand.cc > > > +++ b/gcc/cfgexpand.cc > > > @@ -1214,7 +1214,7 @@ expand_stack_vars (bool (*pred) (size_t), class= stack_vars_data *data) > > > { > > > if (data->asan_vec.is_empty ()) > > > { > > > - align_frame_offset (ASAN_RED_ZONE_SIZE); > > > + align_frame_offset (MAX (alignb, ASAN_RED_ZONE_SIZE))= ; > > > prev_offset =3D frame_offset.to_constant (); > > > } > > > prev_offset =3D align_base (prev_offset, > > > > This doesn't look correct to me. > > The above is done just once for the first var partition. And > > var partitions are sorted by stack_var_cmp, which puts > MAX_SUPPORTED_= STACK_ALIGNMENT > > alignment vars first (that should be none on x86, the above is quite hu= ge > > alignment), then on size decreasing and only after that on alignment > > decreasing. > > > > So, try to add some other variable with larger size and smaller alignme= nt > > to the frame (and make sure it isn't optimized away). > > > > alignb above is the alignment of the first partition's var, if > > align_frame_offset really needs to depend on the var alignment, it prob= ably > > should be the maximum alignment of all the vars with alignment > > alignb * BITS_PER_UNIT <=3D MAX_SUPPORTED_STACK_ALIGNMENT > > In asan_emit_stack_protection, when it allocated fake stack, it assume > bottom of stack is also aligned to alignb. And the place violated this > is the first var partition. which is 32 bytes offsets, it should be > MAX_SUPPORTED_STACK_ALIGNMENT / BITS_PER_UNIT. > So I think we need to use MAX (MAX_SUPPORTED_STACK_ALIGNMENT / > BITS_PER_UNIT, ASAN_RED_ZONE_SIZE) for the first var partition. It should be MAX (BIGGEST_ALIGNMENT / BITS_PER_UNIT, ASAN_RED_ZONE_SIZE). MAX_SUPPORTED_STACK_ALIGNMENT is huge. > > > > > > diff --git a/gcc/testsuite/g++.dg/asan/pr110027.C b/gcc/testsuite/g++= .dg/asan/pr110027.C > > > new file mode 100644 > > > index 00000000000..0067781bc89 > > > --- /dev/null > > > +++ b/gcc/testsuite/g++.dg/asan/pr110027.C > > > @@ -0,0 +1,20 @@ > > > +/* PR sanitizer/110027 */ > > > +/* { dg-do run } */ > > > +/* { dg-require-effective-target avx512f_runtime } */ > > > +/* { dg-options "-std=3Dgnu++23 -mavx512f -fsanitize=3Daddress -O0 -= g -fstack-protector-strong" } */ > > > + > > > +#include > > > +#include > > > + > > > +template > > > +using Vec [[gnu::vector_size(W * sizeof(T))]] =3D T; > > > + > > > +auto foo() { > > > + Vec<8, int64_t> ret{}; > > > + return ret; > > > +} > > > + > > > +int main() { > > > + foo(); > > > + return 0; > > > +} > > > -- > > > 2.31.1 > > > > Jakub > > > > > -- > BR, > Hongtao --=20 BR, Hongtao