Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp25138pxy; Thu, 6 May 2021 19:18:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCvWqzWUBkwiNtj1IMuQ8DufrGFuM/bxNP0Agoh/E2VoG1VGSZHEnUNyXQD7IPrzVPyX6M X-Received: by 2002:a63:a43:: with SMTP id z3mr7312705pgk.331.1620353898809; Thu, 06 May 2021 19:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620353898; cv=none; d=google.com; s=arc-20160816; b=ftJb8KIeZrSYFrI1Srr0l/Ow7pMIjF1t1VUBDD6VUQZsa6rQTmqaeqUkmXI9L7HqRt U+T4mG4EEWqz5q/YIPZm/wKqZbHveTlxbF7wYr1mK5LC1i0DNPhiDiYrkszmvx6jS3Rg eXy6HkL8KUs6cp/ELJz6MwbdtYif8UgDgRcxpj/bPNPXwQBcTjZW5oUvmJ1nrOPVD024 RYiMJBNKDwZXsrptGR1hW0zKPNX3yp517CH0Dvrq0FDvmS5zuQP5tCid8Qd1aucqBAO7 ekz7IasPCBi3kwlebL3HrXVIw6K6tbPRtZEpCuC/rloOW3ceYw+LVaC/PEUMBMn191ub HDRw== 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; bh=+/A5U9OheWry0ATjzo8PrC1Oqruz/cAD+247ifpolkU=; b=yXysotrL6U1Tr5oV21TmOO77Jc1JPOUGncQmf0KeMPJp16pY12+uh36/SNzWjNLBR9 F+shjb7DvXUW2audSDDZZYeSg6DcdXYm/2AhS/z3vy9esV/OsPNavKekmRz4J8Yn0A4M VPtPqGFYRN9R4lIvfVbeWbba+NXOTj5A0OTPhKKP64gbWkBKqM97GGrhFRbg4tRknCxo YQTL4oembs2n97hLhcRQQFeUXviNMbRKUMbenHxtHcQRzsPNagTMbotAuoYJYZ7bIwvH L2KJ7mlbtlr41xzZnPlOi+awOb/Sa5/c1lI+E6hdoZkPIE86jvJgO5Zf/yckX0I5Dfn2 opHA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y23si4652470pfm.56.2021.05.06.19.17.18; Thu, 06 May 2021 19:18:18 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229801AbhEGBvz (ORCPT + 99 others); Thu, 6 May 2021 21:51:55 -0400 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:41950 "EHLO outgoing.mit.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231288AbhEGBvz (ORCPT ); Thu, 6 May 2021 21:51:55 -0400 Received: from cwcc.thunk.org (pool-72-74-133-215.bstnma.fios.verizon.net [72.74.133.215]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 1471olt9020269 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 6 May 2021 21:50:48 -0400 Received: by cwcc.thunk.org (Postfix, from userid 15806) id ABF1115C39BD; Thu, 6 May 2021 21:50:47 -0400 (EDT) Date: Thu, 6 May 2021 21:50:47 -0400 From: "Theodore Ts'o" To: harshad shirwadkar Cc: Ext4 Developers List , Harshad Shirwadkar , Andreas Dilger , Eric Biggers Subject: Re: [PATCH -v2] e2fsck: fix portability problems caused by unaligned accesses Message-ID: References: <20210504031024.3888676-1-tytso@mit.edu> <20210506183017.208802-1-tytso@mit.edu> 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 Thu, May 06, 2021 at 04:30:39PM -0700, harshad shirwadkar wrote: > > -static inline void tl_to_darg(struct dentry_info_args *darg, > > +static inline int tl_to_darg(struct dentry_info_args *darg, > > struct ext4_fc_tl *tl) > > { > > - struct ext4_fc_dentry_info *fcd; > > + struct ext4_fc_dentry_info fcd; > > int tag = le16_to_cpu(tl->fc_tag); > The above line where we dereference tl, this can also result in > unaligned accesses. So, we need to do memcpy stuff for "tl" too. > Changing all access of tl to a memcpy-ed local variable is itself a > big change which I'll send along with your patch. Ah, I didn't realize that 16-bit shorts could be misaligned. With the jbd2 checksum v2, that wasn't an issue, since the entries were always an even number of bytes, so it was only the 32-bit accesses that were problematic. But yeah, if the dentry is an odd number of bytes, we're not padding that out. > > > > - fcd = (struct ext4_fc_dentry_info *)ext4_fc_tag_val(tl); > > + memcpy(&fcd, ext4_fc_tag_val(tl), sizeof(fcd)); > > If we do the memcpy fix here, ext4_fc_tag_val macro becomes unusable - > since at this point that macro just does (tl + 1), which will fail on > a memcpy-ed version of "tl". Well, we can make define them as: /* Get length of a particular tlv */ static inline int ext4_fc_tag_len(struct ext4_fc_tl *tl) { __u8 *p = (__u8 *) tl; return *cp + (*(cp+1) << 8); } /* Get a pointer to "value" of a tlv */ static inline __u8 *ext4_fc_tag_val(struct ext4_fc_tl *tl) { __u8 *p = ((__u8 *) tl) + 2; return *cp + (*(cp+1) << 8); } > Interesting bit is that even the kernel does these kinds of accesses > in the recovery code. I have a suspicion that these unaligned accesses > are the reason why you see failures on sparc? Yeah, it could be that arm allows unaligned 16-bit dereferences, which is why this isn't blowing up on armhf and armel. But at least with this patch, armhf and armel builds aren't blowing up, and UBSAN is happy. (Although I wonder why UBSAN isn't complaining about the unaligned 16-bit dereferences.) - Ted