From nobody Fri May 3 18:56:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524493004343135.52908137081545; Mon, 23 Apr 2018 07:16:44 -0700 (PDT) Received: from localhost ([::1]:50521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAcGm-0006CU-Hr for importer@patchew.org; Mon, 23 Apr 2018 10:16:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35766) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAcEy-0005BA-NC for qemu-devel@nongnu.org; Mon, 23 Apr 2018 10:14:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAcEu-0002gJ-1e for qemu-devel@nongnu.org; Mon, 23 Apr 2018 10:14:48 -0400 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:34388) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fAcEt-0002g2-Tx for qemu-devel@nongnu.org; Mon, 23 Apr 2018 10:14:43 -0400 Received: by mail-qt0-x243.google.com with SMTP id a25-v6so17809174qtm.1 for ; Mon, 23 Apr 2018 07:14:43 -0700 (PDT) Received: from x1.local ([138.117.48.212]) by smtp.gmail.com with ESMTPSA id b6sm10004821qkg.7.2018.04.23.07.14.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 07:14:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+/JrC9dGy4vbjCAwPgULSx6HlJyEbXPBxt24d2aZra8=; b=BPoZeHkro4+7QrEpttJsMAGCvM27C27EkqELvM4a26yoQ7UAhPeleLVSpI1b3YHoJt 4TL69PPQDkmKf8C2dqLIbLHgIG/oeiqVP6ftpW7+pD4KGexbzFlHuc8XyRLUUwBmq1Fo sHXmLrVjZgYOc8IlifSzzHX4okZL9h6d1aLKreUD8lu4l9B4HieFEqu/3jJvK96d94BN qTWr4wh+t0uPyMsX6juEab4pxhEd4jBjMBMbugMePc4qH/QG8/chJxfhhjh/jXmeOKrc z57OBhb8FxwnUXbwATyPFAFeKLncQjz30Idne8TYsn/JWUBEp1nPDXwRe463P6sYIpoJ wr2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=+/JrC9dGy4vbjCAwPgULSx6HlJyEbXPBxt24d2aZra8=; b=tik9rBZDaJLqoOXUcEu0PZEd9ASm0hDul50N5p3lMlc5+ypX+ZDWm+2plp3dl+Elg9 MMBjMBS0r4pYF4VexmjSpQ8/4OAUI4/MS5Q2Mh9/RjxEGJsZxeoTrYWAF6ZQ1Kegq922 jRV4W3pPpR01V0KoMsqXCWnqY64HcZm0/COMkcTnVaXWAd3TmebSwqjYG0xJ4vho9+YN fUEFCdEXqxJoWVZWZ5eLsDQ3Ch7TjBQtdbAoSHpu6vPKuq+hmuVqEGDS2HnAWoDjgn+8 mdSj13MYVcrJgnqBBQv+BkqskNEjsqeBJdRGfSB3L9khYwKUIVItuKcSPgrVDE6d3Fl5 xjmA== X-Gm-Message-State: ALQs6tD2GUPDljHRrvna1HWxaPn6FlHIvGzjkkcgiZ4vK+HJs63BLqO7 rm6QMu6VcgHvxn06Ke7Grg0= X-Google-Smtp-Source: AB8JxZrMWN9B1VWqELew+nuNkbaeWG+vjT6vgKjClgkmkeweGvD8zL3wiUOA6snhyZhiXnfuvzFgTg== X-Received: by 2002:ac8:1483:: with SMTP id l3-v6mr23310862qtj.17.1524492883476; Mon, 23 Apr 2018 07:14:43 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: David Gibson , Peter Maydell Date: Mon, 23 Apr 2018 11:14:36 -0300 Message-Id: <20180423141436.12172-1-f4bug@amsat.org> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::243 Subject: [Qemu-devel] [PATCH v2] loader: Fix misaligned member access X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paul Burton , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 This fixes the following ASan warning: $ mips64el-softmmu/qemu-system-mips64el -M boston -kernel vmlinux.gz.itb = -nographic hw/core/loader-fit.c:108:17: runtime error: load of misaligned address 0x= 7f95cd7e4264 for type 'fdt64_t', which requires 8 byte alignment 0x7f95cd7e4264: note: pointer points here 00 00 00 3e ff ff ff ff 80 7d 2a c0 00 00 00 01 68 61 73 68 40 30 00 = 00 00 00 00 03 00 00 00 14 ^ Reported-by: AddressSanitizer Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- v2: do not change the 32-bit access, add comments (David Gibson) hw/core/loader-fit.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hw/core/loader-fit.c b/hw/core/loader-fit.c index 0c4a7207f4..c1c7c9c119 100644 --- a/hw/core/loader-fit.c +++ b/hw/core/loader-fit.c @@ -94,6 +94,7 @@ static int fit_image_addr(const void *itb, int img, const= char *name, { const void *prop; int len; + fdt64_t fdt64; =20 prop =3D fdt_getprop(itb, img, name, &len); if (!prop) { @@ -102,10 +103,18 @@ static int fit_image_addr(const void *itb, int img, c= onst char *name, =20 switch (len) { case 4: + /* Assuming the base of the fdt is aligned, then fdt_getprop() + * returns 32-bit aligned properties, so this load is guaranteed + * to be 32-bit aligned. + */ *addr =3D fdt32_to_cpu(*(fdt32_t *)prop); return 0; case 8: - *addr =3D fdt64_to_cpu(*(fdt64_t *)prop); + /* Since the property is not guaranteed to be 64-bit aligned, + * use the stack to avoid an unaligned load. + */ + memcpy(&fdt64, prop, sizeof(fdt64)); + *addr =3D fdt64_to_cpu(fdt64); return 0; default: error_printf("invalid %s address length %d\n", name, len); --=20 2.17.0