From patchwork Sat Oct 5 16:48:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 832991 Delivered-To: patch@linaro.org Received: by 2002:adf:8b52:0:b0:367:895a:4699 with SMTP id v18csp1283320wra; Sat, 5 Oct 2024 09:49:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUx3p2l3b4/AakAS4tHSigjB/UGKbRuW5C2ZJMT3TL2jFzL4J6fSHTu7JejUKgTCyljsAYX8A==@linaro.org X-Google-Smtp-Source: AGHT+IE5rkRYjR7vT2/cIqz9Jy40FSjwu9zDnwJoAUL6FMQoWVhYzSPnC+gZ5WpV1x38VzbIZCo8 X-Received: by 2002:ac8:5f0e:0:b0:45d:8e45:7969 with SMTP id d75a77b69052e-45d9ba69c67mr95141821cf.33.1728146991377; Sat, 05 Oct 2024 09:49:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728146991; cv=none; d=google.com; s=arc-20240605; b=f73qJpr4yJYdempGjQCw73BfqwC5Yl2y7QXDYpsDQLe+4uqumZKl0fTg1N6q3S/oCJ fax3QV8VHebMvD9bXSDVla+wq5lMXlICZk3jr10KParComkYmO1+xtY7IVjzcCK0FXp4 RfRkf8Sidym74e7/QUB009e8K8DMChz2ACq3Fb49iiWJgus4owoWuaYngFR0/Dlz5Hcd yczbmCNqLBus9ad5/xYY4lG7aqtJOEw0HZF+chhWS4tozVSw9IaZ3IG9TaZfIdsDn8X+ +bDBzzb1dECpUnen/q7V6jjEA/G5Vil1FJUPIIS+zw9M7PqMxRMDXdrQmIEwzKraMcK5 nm2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=iSrAwBk5bZNjn8Zy9dmgJJyBe5UY35yHEd3GQKBCY9s=; fh=xsy+IYpDysuYwRiEGHtZS+ytVQlJJO4jvtHp2Z5YndQ=; b=LaxwxASGGwD4mimZZWFvvMOFvbGUv28O9mXnvMJM6laLq8NWFtA7QmOSRZfq8A8Kmu F2HSU69inTEa82XjXv5jGxgz0nJVqg7yDhELAbITHBnpZTB+3aNco5DD/NV9kM8/GeZ6 19SDw72gK99GVIzbhS3znGkaN5dtm2Fj0a4kxjcPsTgvyS0vgP9Qqykn1QL10U69Tbru 97gRJowDMEOiT+vP8/98dhG7QuyM4R6hs8bWJqZPwsE8BoS5Dbu0O5HmqcLyCTxRqvv5 fOIuubZNMMz4ZHP4sH/Jy+WoJa13qOXlChu18yUbpkjGoHkJSjgg86EkLa4B76OSDNji BZtA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DITQYRdl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45da76b792bsi24555661cf.648.2024.10.05.09.49.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Oct 2024 09:49:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DITQYRdl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sx7xh-0000qG-8V; Sat, 05 Oct 2024 12:48:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sx7xe-0000ps-FH for qemu-devel@nongnu.org; Sat, 05 Oct 2024 12:48:54 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sx7xc-0001dt-Fx for qemu-devel@nongnu.org; Sat, 05 Oct 2024 12:48:54 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-2e0afd945d4so2353758a91.0 for ; Sat, 05 Oct 2024 09:48:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728146930; x=1728751730; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=iSrAwBk5bZNjn8Zy9dmgJJyBe5UY35yHEd3GQKBCY9s=; b=DITQYRdl1swQoyMDsXKkCOgW6axBDTsJmssDJrwNyvwvYby36+8MKwPlbdMOOP7UOh 12sF+RfZjpxk56WenEYPIBUWZ8mo9LobA+39ohsi+kXtJc/namoDKXxaHYyXkk54YbY3 QohKCqSSWEZFYJzuOmB4RnyTp1+Ike0yq4AR6xxhAAIbI3fZ/+3+em4vRonWGOHu9b/g /X2okF+8XNwZGZCJY84dS/7V83Upnxqp+c+Ct+N/zX1+PSrUg6BbIjPaOp0GgCGt//QA RpYLOtKoZ6lqBT8ukPRekeQuvO76XWmgOztmi219x/s46jRZaIMXrktkItKelwiHP+M5 epzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728146930; x=1728751730; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iSrAwBk5bZNjn8Zy9dmgJJyBe5UY35yHEd3GQKBCY9s=; b=A6TEcZ04WQ9+8SN57zVVlxpeAx9xdFyOHgAJ8OeahF0CMSN892/l9lCWnnXl9n5TfG 1F68iwI0mmBU09dt15Y8TLwwh72M51u7wTJhpgN6NCFEmCGrt0x1uwkC9naDJtjB+2v2 gnAvFMy0CTarDxFBVtZRQNN3MzSLfQqKN8V8XNDEnX73z1LwI12hfQrxfiJn5dzaiGbd d0yXxuNhZtgYl6UPbnJAZCD9aLlnY5urF4jRAyKq92bRTkVIbsu4KCYm4MJwRPQQYvZm emwvQgZJ7Bau2M+hgDh3jieYyXANu7BOkFWlYALxaj818NQwxcSAMrwMxNrpfe2G0oq0 03Ew== X-Gm-Message-State: AOJu0YxPBamN3SL9BnvSsRwfrjSjPzfu4u5puGn8WaSJaJSPeysLVHrv L8FwHk7HkZ+/RPOOLaBZZtfl8wBNL0WstQ1ekx/11YX9t9nEdC8UVWIfXmmI+JqcRcEHaDSbRLx C X-Received: by 2002:a17:90a:c7c9:b0:2e0:a4a4:75d9 with SMTP id 98e67ed59e1d1-2e1e622860emr7885380a91.12.1728146930528; Sat, 05 Oct 2024 09:48:50 -0700 (PDT) Received: from stoup.. (174-21-81-121.tukw.qwest.net. [174.21.81.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e1e8665529sm3787753a91.39.2024.10.05.09.48.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2024 09:48:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru Subject: [PATCH] linux-user: Fix parse_elf_properties GNU0_MAGIC check Date: Sat, 5 Oct 2024 09:48:49 -0700 Message-ID: <20241005164849.424838-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Comparing a string of 4 bytes only works in little-endian. Adjust bulk bswap to only apply to the note payload. Perform swapping of the note header manually; the magic is defined so that it does not need a runtime swap. Fixes: 83f990eb5adb ("linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2596 Signed-off-by: Richard Henderson Reviewed-by: Michael Tokarev --- linux-user/elfload.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 0678c9d506..52c88a68a9 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3121,11 +3121,11 @@ static bool parse_elf_properties(const ImageSource *src, } /* - * The contents of a valid PT_GNU_PROPERTY is a sequence - * of uint32_t -- swap them all now. + * The contents of a valid PT_GNU_PROPERTY is a sequence of uint32_t. + * Swap most of them now, beyond the header and namesz. */ #ifdef BSWAP_NEEDED - for (int i = 0; i < n / 4; i++) { + for (int i = 4; i < n / 4; i++) { bswap32s(note.data + i); } #endif @@ -3135,15 +3135,15 @@ static bool parse_elf_properties(const ImageSource *src, * immediately follows nhdr and is thus at the 4th word. Further, all * of the inputs to the kernel's round_up are multiples of 4. */ - if (note.nhdr.n_type != NT_GNU_PROPERTY_TYPE_0 || - note.nhdr.n_namesz != NOTE_NAME_SZ || + if (tswap32(note.nhdr.n_type) != NT_GNU_PROPERTY_TYPE_0 || + tswap32(note.nhdr.n_namesz) != NOTE_NAME_SZ || note.data[3] != GNU0_MAGIC) { error_setg(errp, "Invalid note in PT_GNU_PROPERTY"); return false; } off = sizeof(note.nhdr) + NOTE_NAME_SZ; - datasz = note.nhdr.n_descsz + off; + datasz = tswap32(note.nhdr.n_descsz) + off; if (datasz > n) { error_setg(errp, "Invalid note size in PT_GNU_PROPERTY"); return false;