From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5BEA53858C55; Sun, 3 Mar 2024 07:22:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5BEA53858C55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709450530; bh=ta+X0BVTtx3eQo0TEdabT+AygVR9CWshAmxK96CbyuU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kuTAmc6gRc5ts1F0U7JqNQvnT6xnqpJ5vnfwBVRS4KYgXckBtbPv/AeFA0yIZciFz 1RSNYurgJSviPg8JKliah6EY6sX4O0NsqFwUMWhotGURzwX58b+V71vjrvOBg0HF/O Dar8h+a3EEvfESzlP/dXwq6wXP6fvnL9wKTz5o6w= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/114217] -fsanitize=alignment false positive with intended unaligned struct member access Date: Sun, 03 Mar 2024 07:22:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114217 --- Comment #4 from Andrew Pinski --- https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/inc= lude/asm-generic/unaligned.h?h=3Dv6.7 is correct except it should not expose get_unaligned/put_unaligned since the undefined code happens way before. The problem is with the btrfs code in btrfs_filldir: ``` static int btrfs_filldir(void *addr, int entries, struct dir_context *ctx) { while (entries--) { struct dir_entry *entry =3D addr; /// THIS IS BROKEN and ca= uses the -fsanitize=3Dalignment error char *name =3D (char *)(entry + 1); ctx->pos =3D get_unaligned(&entry->offset); if (!dir_emit(ctx, name, get_unaligned(&entry->name_len), get_unaligned(&entry->ino), get_unaligned(&entry->type))) return 1; addr +=3D sizeof(struct dir_entry) + get_unaligned(&entry->name_len); ctx->pos++; } return 0; } ``` Added comment on where the error comes from. The get_unaligned macro really should not be used here. What should be used here is an unaligned version of `struct dir_entry` instead.=