Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp4469414rwb; Sat, 21 Jan 2023 12:37:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXvXZUBgbJSxtzKae+LfHbN0xf4dfcu3TlDK/Iwvx1uDX3hnT3X4sNgSCPr3myQG7iPMMT0z X-Received: by 2002:a17:90a:d585:b0:227:c69:3ca7 with SMTP id v5-20020a17090ad58500b002270c693ca7mr20529988pju.10.1674333470458; Sat, 21 Jan 2023 12:37:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674333470; cv=none; d=google.com; s=arc-20160816; b=J4jUjMMpp3XeijxLWjbD1vb+2sskJ+FGaA+1y561qwEGc0E6r6U5xmEhVxq+h2+bsN nS0z7WZmsx6UwztRspp3EsfoLeu0bB4FHCyoVrzTjjFHbmMmEx1LQ3F23Lrq4Us8Pz0i 3M++Cm3O9dWNPM5EB/o1sVYeyFxaDxjU/5ggCCkF0ZH2kqAwD93N3UXbAoX7WHa0JhKA Mx9XuZF4ki+MGdQQ6mupq7qUSLU00mza5dp5mb7euAuWUk+/Nt+yz6cHPU+5X8unNzg6 HPJLZjOCxPUNWLv3mtWT1m7y39sdN1O0HdX0sNCMokvyMEE1WPeN/KJ1lhEQOCPf1+Rl RmTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Iogt+cOrSEZJELrp4mxqPn1+KPUdewPqC5B6X65KOCw=; b=TCFnE/O/taiFvRyYgg0E2/ul+R8ESMOvDL/xtL/dhWtU5YL/YB3Gh926dTqN1/Hr0l i3M23jYEw94KUBotG9Vn94pPMK4hhv6DU/zD/KQdFaAf1lB3iaI4A6gdSyaGZR8qudIY kkxxErue6OsWFhGNkKbFGHRmok2AA9SPb0RlzaD47YtGFyk1X5iAGwGgCEuDe6HjCsuD cXxzannZXIICZUlKajc9qMwlxG8L2jn/XWvikyM8SaKLXQjz7aerlhsAJ2ICJDP7Y0oP 7ponJ2v+444vJRAEL/ApbYYDsh5ev+9Ky6nzQnLLplE3razVfDakodux8oFvgE4nHOoK nISA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hB2pT9Io; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t21-20020a17090ad15500b002262476fc44si5950215pjw.178.2023.01.21.12.37.29; Sat, 21 Jan 2023 12:37:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hB2pT9Io; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229741AbjAUUgn (ORCPT + 99 others); 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 Content-Transfer-Encoding: 8bit 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); -- 2.39.0