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 EAE123858D33 for ; Tue, 26 Mar 2024 03:27:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAE123858D33 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 EAE123858D33 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=1711423626; cv=none; b=PElhforo1oSHipq9Hu15QoWFt/4NxppC9nzmQJYy0HoibbS0KBdI7YVUAAWQ4qh6jWRmo+rpG5YQUkxeeKiVhoDpBWH5JGJurXtaTXzIfUYd3keE170b9ZQcu5hVGvGaBHlHHOomIBNFhAAIOCjHtE54LmRjIb14jchi+5Fc/WY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711423626; c=relaxed/simple; bh=1bsRj8Bl5jf5vM1fr7kCcBItQ7g1P1/8CLZmNdXlblY=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=pZEfWjh3ChsZ0EkPF/zhupKToPQl0E40xuy8XymJfWmaD26XSTkYdHTfJ3Ytm+7DlK8FK4lxjjBCklMq0bnwjcoXQdHbzTTfMt/4+ejsKns9iXUiicaTpr9jfeMZ5xCcEU+oMopygIO4vKrOK0zRWB4dnNF8vmO5WOK1QdtXnwg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-6918781a913so42536266d6.3 for ; Mon, 25 Mar 2024 20:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711423623; x=1712028423; 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=GrikenzhrHdzrGBjDzBuO8xcc1w03EkVSwEn3UilWRM=; b=H/X6IPPrdYcmCbYDVuxK27PsubmUaLgoRjqEmTXdiB3WPJbCsNOcC0WQlK/heQJilN 8vlPmKSlmU2BOZ+kgYK10MsQLgUu9hLAN9dNNmFOavr3VqOnexpxXkAEaCQ2RYBhGYH5 OWB6njDDKaCoGB84tZ12dHhAieovCoRx3wxh4QiwqzYMw36ENfARxXKEr1m/ahlwfdR6 d+2J+EXbRXwpNQakwJpY4PfdbrRYz0E3AusqBFpkggeQ3Mo3AiXvjcd/8AkjBGyHasvA 5Kn1163DiYgmvTil4/T/hX17RegP3q+vJZ+V0okF00LD5qxkr6Bw/1LIrKPg5wlC0wU1 R4tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711423623; x=1712028423; 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=GrikenzhrHdzrGBjDzBuO8xcc1w03EkVSwEn3UilWRM=; b=eyHSou59ywUgnlXEB9/FoZA+u6U8h7Keli1pI7x6viF9HTstM9n7J6cHtaeKsFxSL0 H3YgHieNG+uuKOz5uN/lX3qsjPdnH9CsR509ZGBrCqQ6B+M5pPDNTFOCvUaQlxkkdQP+ 2aOhGYEjTIA5PE0x3UkDZyMQDqSANeOy9rlb7VsxGFxdDwJLh2YMprIMiuE6ug0SV68p MOPH+jCRGF5ion16x1G245E/CkPYbQ+pKJMNnd3aSZxUefB2Wzx1YPkHCMk6faU10Pdd pq/A9unS28UigsPIONREzrbD0J3CAIy+zPo3iEKHhnMd2oFcZAztVLe6HaeKH3OO/mh3 L+9Q== X-Forwarded-Encrypted: i=1; AJvYcCXR1/jvdHyZ5cqL9CcOWFhB0eq3yfroTR9M3TbgdsBkgn9qb2ll9mmXvPHObzyo3iBdaabb1lxcXbwaQrKcfoL/gr2kuHECbA== X-Gm-Message-State: AOJu0Yxf3AVNJhyZhN8ZIWVxdIHg+RRxj/TmCLEHUCEKQdqHPAICqpoL bAQmsKrr7P0iKzbbUcngQMv2cKc70FBB7iG0dPvN5g2WLbwKDQ2Y+t6lWl7+vTEN2GugFQwIWWI TE2DgqQ5YM3Tg/cwP8itjMgoPcPI= X-Google-Smtp-Source: AGHT+IFsjNl7lyUdhBSHgwBUyC3LeLHFw5Mc9PblLCcs0TqX6oRQ41MEL6ixL3f2Y7R7jHY9TKQiCOPaLiSN5O1OAZk= X-Received: by 2002:a05:6214:dc5:b0:691:826f:5060 with SMTP id 5-20020a0562140dc500b00691826f5060mr11928083qvt.10.1711423623219; Mon, 25 Mar 2024 20:27:03 -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:26:51 +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.5 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 Mon, Mar 25, 2024 at 8:51=E2=80=AFPM Jakub Jelinek wr= ote: > > 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, and > > 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 s= tack_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_ST= ACK_ALIGNMENT > alignment vars first (that should be none on x86, the above is quite huge > alignment), then on size decreasing and only after that on alignment > decreasing. > > So, try to add some other variable with larger size and smaller alignment > 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 probab= ly > 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. > > > diff --git a/gcc/testsuite/g++.dg/asan/pr110027.C b/gcc/testsuite/g++.d= g/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 > --=20 BR, Hongtao