From patchwork Sat Jan 21 20:32:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 1730043 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=gbep=5s=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=hB2pT9Io; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Nzp7M6fRfz23hM for ; Sun, 22 Jan 2023 07:36:47 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Nzp7L53WYz4y06 for ; Sun, 22 Jan 2023 07:36:46 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4Nzp7L4s6Fz4y0B; Sun, 22 Jan 2023 07:36:46 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=hB2pT9Io; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Nzp7L4gKnz4y06 for ; Sun, 22 Jan 2023 07:36:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229764AbjAUUgn (ORCPT ); Sat, 21 Jan 2023 15:36:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229687AbjAUUgm (ORCPT ); Sat, 21 Jan 2023 15:36:42 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0263D28D3E for ; Sat, 21 Jan 2023 12:36:41 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8038760ADD for ; Sat, 21 Jan 2023 20:36:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2018C4339E for ; Sat, 21 Jan 2023 20:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674333399; bh=IRtFKx1Qv/BeXJIpY4N5ZFn3oUsQkx1zaMi9+y9XAAM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hB2pT9IoMRtbID42+4+nFdbMbwplG3jCUwO0ij0o4ve/PNKvbjsQBlYzj5ma+ik8g xGik4EKvKiSMhzlVVK/vPy9SkbkvN7sYsifzgxzfqu8/9C8qTvel+Igi3+Ki5L0qav fcAT0I5z95hYrlNsdmFs5+mXrdSe9EVayWFUqbQ0bTrDcoNzsgajFvN5JsbAiKlVe9 KSxGdYRyRbrGWR5GMSwSx27ETD1DGHpEL0X3YlZUXAURFLJMnMkcAmUiwW5akO4zgt skWcIE+Gt5m987ED18uG731+aXr3HIHOxtm4iNLu9uXaba0IldYYWOWXbCYE6zAOAh 82IUYX2AIfJKg== From: Eric Biggers To: linux-ext4@vger.kernel.org Subject: [PATCH 08/38] lib/blkid: fix unaligned access to hfs_mdb Date: Sat, 21 Jan 2023 12:32:00 -0800 Message-Id: <20230121203230.27624-9-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121203230.27624-1-ebiggers@kernel.org> References: <20230121203230.27624-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers With -Wall, gcc warns: ./probe.c:1209:42: error: taking address of packed member of 'struct hfs_mdb' may result in an unaligned pointer value This seems to be a real unaligned memory access bug, as the offset of the 64-bit value from the start of the buffer is 116, which is not a multiple of 8. Fix it by using memcpy(). Do the same for hfsplus to fix the same warning, though in that case the offset is a multiple of 8 so it was defined behavior. Signed-off-by: Eric Biggers --- lib/blkid/probe.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c index b8b6558e3..6a3bb2478 100644 --- a/lib/blkid/probe.c +++ b/lib/blkid/probe.c @@ -1198,7 +1198,6 @@ static int probe_hfs(struct blkid_probe *probe __BLKID_ATTR((unused)), unsigned char *buf) { struct hfs_mdb *hfs = (struct hfs_mdb *)buf; - unsigned long long *uuid_ptr; char uuid_str[17]; __u64 uuid; @@ -1206,8 +1205,8 @@ static int probe_hfs(struct blkid_probe *probe __BLKID_ATTR((unused)), (memcmp(hfs->embed_sig, "HX", 2) == 0)) return 1; /* Not hfs, but an embedded HFS+ */ - uuid_ptr = (unsigned long long *)hfs->finder_info.id; - uuid = blkid_le64(*uuid_ptr); + memcpy(&uuid, hfs->finder_info.id, 8); + uuid = blkid_le64(uuid); if (uuid) { sprintf(uuid_str, "%016llX", uuid); blkid_set_tag(probe->dev, "UUID", uuid_str, 0); @@ -1243,7 +1242,6 @@ static int probe_hfsplus(struct blkid_probe *probe, unsigned int leaf_node_size; unsigned int leaf_block; unsigned int label_len; - unsigned long long *uuid_ptr; __u64 leaf_off, uuid; char uuid_str[17], label[512]; int ext; @@ -1274,8 +1272,8 @@ static int probe_hfsplus(struct blkid_probe *probe, (memcmp(hfsplus->signature, "HX", 2) != 0)) return 1; - uuid_ptr = (unsigned long long *)hfsplus->finder_info.id; - uuid = blkid_le64(*uuid_ptr); + memcpy(&uuid, hfsplus->finder_info.id, 8); + uuid = blkid_le64(uuid); if (uuid) { sprintf(uuid_str, "%016llX", uuid); blkid_set_tag(probe->dev, "UUID", uuid_str, 0);