Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3806673pxy; Tue, 4 May 2021 10:18:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxa1KeJLfYv8dWj7djx9A4bUk7+ZaI3x2j3utADad9+p0XHBpA9NLK8xC+BTWEFf3TmWPpq X-Received: by 2002:a17:90a:1016:: with SMTP id b22mr17538839pja.128.1620148685433; Tue, 04 May 2021 10:18:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620148685; cv=none; d=google.com; s=arc-20160816; b=MrwypKMPTpolMxPr/XXdy5e6VUFh2H3D++WHkNwCcTzGv5Yl+cu82KXnJ9FtOrxdsE PkoLDZ4TuiA7c9P+S0o+4QoZNdYVjMDBNbuez0h3naaUKA+qC5mqs7DTxZHqT6TLqjNc IGvN75z1Rup6q/ZnngY+R0LEnksJa2asu2qxQtRBm4X1U6O0akM5Uleo29APE67S9oGs KC0DWbWwIOGNkgCZUzDca2EWRdFlc+/S2gvSdzOBtPf5jOgI4m48RkMpSuDRNjB3aOar Y3twe+E0MLHPRlGJeYA8rF6y3yswsSFhNc81n+mBDksUqijdsDqPJMM1qSt1NKWXwisx 2Gzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=beuU0WtimLc+6scINoYhbg1CIyLxp7rqcCb2LpObWAI=; b=fAp3w00OeU+5JSuSXShzvCZZw7rGf5gdkMV8YvZ68syWG5+Yqo/xZqtaDOlTwgHoP3 Rao2wtTtYOsOg5qjqRkBwy0aQtfG23T3sqemdEYsiZe7orNsY+7CJV/pkvJ6Q2DHXKV/ ykdIsiNcCQbXv8DDzgVOg66vStHvTNyYp/aUI38MGA1cGg2odOXGAvKl3adiKnztPDU/ OsKC2zJOXPIsEqrMOTSpOok9dG7wNqogtnINm+ADcxVF1DBY1cp9H6Lzvdmokpwuctan gUjXfURcwO63g+hxuJjgekznCUaMYYLL1R7Zdg7wtZSNQVzFMVrSvzBbeP9H83SwPkzk MfyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s4EAkP4i; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t17si17371543pfc.128.2021.05.04.10.17.46; Tue, 04 May 2021 10:18:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s4EAkP4i; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231665AbhEDQrb (ORCPT + 99 others); Tue, 4 May 2021 12:47:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:41428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231651AbhEDQrb (ORCPT ); Tue, 4 May 2021 12:47:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5449561177; Tue, 4 May 2021 16:46:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620146796; bh=i0tTuwc4foqr9yTwvqzWG/APvDlsilAQ9NxZY10SsGo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=s4EAkP4io4/Lbvw/7DmV9VOnfBGLHXtrQeapy2ZtUQ01lTRcBzFTqJ79LEixbHw+O 3knjvTlglJ755U4Pr15LIco2noY5vpr4A/SRP4ytLghO6xC/Is0e41bxAZxcHjQuNT Xq82IhbIdS5bTPB96T0Pcy1aweP3SdEr9UocO9UVBI9Ckgyli7ywkLxdkId5WPSyXf nx+BL1sHquL3yv8lLgS9YbXDlfiUN9o/VWNwRa2T/nbM88StfUpU6zvezo+5dlmC7w j7F/vH3ZgNWQLKMtsqQT48P6J53K7Q49tNyM/vIn8upNYGqEAIstnbhkttn9vb7acQ fxy7V7NIJvt6Q== Date: Tue, 4 May 2021 09:46:19 -0700 From: Eric Biggers To: Theodore Ts'o Cc: harshad shirwadkar , Andreas Dilger , Ext4 Developers List , Harshad Shirwadkar Subject: Re: [PATCH] e2fsck: fix portability problems caused by unaligned accesses Message-ID: References: <20210504031024.3888676-1-tytso@mit.edu> <8E9C71E8-FE5F-4CB8-BA62-8D8895DCA92A@dilger.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Tue, May 04, 2021 at 09:49:15AM -0400, Theodore Ts'o wrote: > On Tue, May 04, 2021 at 02:40:08AM -0700, harshad shirwadkar wrote: > > Hi Ted, > > > > Thanks for the patch. While I now see that these accesses are safe, > > ubsan still complains about it the dereferences not being aligned. > > With your changes, the way we read journal_block_tag_t is now safe. > > But IIUC, ubsan still complains mainly because we still pass the > > pointer as "&tag->t_flags" and at which point ubsan thinks that we are > > accessing member t_flags in an aligned way. Is there a way to silence > > these errors? > > Yeah, I had noticed that. I was thinking perhaps of doing something > like casting the pointer to void * or char *, and then adding offsetof > to work around the UBSAN warning. Or maybe asking the compiler folks > if they can make the UBSAN warning smarter, since what we're doing > should be perfectly safe. This does seem to be an UBSAN bug, although both gcc and clang report this same error, which is odd... Dereferencing a misaligned field would be undefined behavior, but just taking its address isn't (AFAIK). > > > > > I was wondering if it makes sense to do something like this for known > > unaligned structures: > > > > journal_block_tag_t local, *unaligned; > > ... > > memcpy(&local, unaligned, sizeof(&local)); > > I guess that would work too. The extra memory copy is unfortunate, > although I suspect the performance hit isn't measurable, and journal > replay isn't really a hot path in either the kernel or e2fsprogs. > (Note that want to keep recovery.c in sync between the kernel and > e2fsprogs, so whatever we do needs to be something we're happy with in > both places.) > Modern compilers will optimize out the memcpy(). However, wouldn't it be easier to just add __attribute__((packed)) to the definition of struct journal_block_tag_t? - Eric