From patchwork Mon Dec 10 11:26:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 153258 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3447098ljp; Mon, 10 Dec 2018 03:26:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/XgLldK0qylV+Fcfanj4EhUZvomlqdSuuF9jSVjUXcae4j8IbRutfhjXpxbO2+QLeI2tngZ X-Received: by 2002:a62:8d4f:: with SMTP id z76mr12410363pfd.2.1544441216285; Mon, 10 Dec 2018 03:26:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544441216; cv=none; d=google.com; s=arc-20160816; b=IgjHE8a3D6zQR0hh7RHHan7tmaAG4iAIMFjIP4I5zp29wK6z8XaD48rShpG59JBami gxinNlBGLASFH6t8rv2UXyQrZ9XHo1pFxkGjyIJX3KhjOQYqQOiUK+qz7BL00bDtHIEL vwElkPmLDnhll2Ca4q+wS3JxcBra5GKr6x/vUMFxHBdxTi81oreVk08AFDBt6PVuDDhJ pOzz+8+OdXXMMattQTfATPbHDD5eQSYwL5i9yk5iRvGDNvh8NL3exOSK/jPuYiSNw4KH /Q9XvYNIvNNsu2v8WsoliIi3149TqX9E6EdW4i6BZno3VKSs+bVOxVQ32EpqBlQ/53an j8Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=fwjf29Q1ACvnsQ4zL95SZ8aHAA9F0FgOfChGG3Tl6V4=; b=wviXiZqDK9uZrOvMm0sQLFek3agYG6sAcE1qxHY4tUevgGVoFv/eHxwP16XG7T6EHj BSAPpvVftFfoFkI2eh5lit0THh0D5bUuoX52u3mzKK51YUl/EYFgN1TUR8O6y9fUML+j 0cFPu6NunpB7GF1cYIkVh7AAJuWn8KqOw/12SExyUo7vR95+zT1IeggA0Dg7/VSLM6tQ LUlwxgMm/SG14jUtANvSUq6OH4pEJ+AhoFerE0PugHsem8NPjgF4SbRb21O1evbEuH+W e0S0+WkvA+OzdiLgSn0DnkDoGbJ1Dlizet89DlxhfapR/5DpMR7hBVYvs/5RlwWKvhGA nG0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id o11si9568113pgd.234.2018.12.10.03.26.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Dec 2018 03:26:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gWJi7-0008CU-1J; Mon, 10 Dec 2018 11:26:51 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, qemu-block@nongnu.org, Fam Zheng , Igor Mammedov , "Michael S. Tsirkin" , Ben Warren , Max Reitz , Kevin Wolf , Stefan Weil Subject: [PATCH 1/3] block/vpc: Don't take address of fields in packed structs Date: Mon, 10 Dec 2018 11:26:47 +0000 Message-Id: <20181210112649.11581-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181210112649.11581-1-peter.maydell@linaro.org> References: <20181210112649.11581-1-peter.maydell@linaro.org> MIME-Version: 1.0 Taking the address of a field in a packed struct is a bad idea, because it might not be actually aligned enough for that pointer type (and thus cause a crash on dereference on some host architectures). Newer versions of clang warn about this. Avoid the bug by generating the UUID into a local variable which is definitely safely aligned and then copying it into place. Signed-off-by: Peter Maydell --- block/vpc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.19.2 diff --git a/block/vpc.c b/block/vpc.c index 80c5b2b197e..968d80ae461 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -979,6 +979,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, int64_t total_size; int disk_type; int ret = -EIO; + QemuUUID uuid; assert(opts->driver == BLOCKDEV_DRIVER_VPC); vpc_opts = &opts->u.vpc; @@ -1062,7 +1063,8 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, footer->type = cpu_to_be32(disk_type); - qemu_uuid_generate(&footer->uuid); + qemu_uuid_generate(&uuid); + footer->uuid = uuid; footer->checksum = cpu_to_be32(vpc_checksum(buf, HEADER_SIZE));