From patchwork Sat Nov 9 06:38:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 842065 Delivered-To: patch@linaro.org Received: by 2002:a5d:6307:0:b0:381:e71e:8f7b with SMTP id i7csp2029137wru; Fri, 8 Nov 2024 22:43:09 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUKTNvhH5vXLHCcsSpbdD1hJWVZ8r2577RMKLhm1ozfXJksWbHwIfqGmp1IW0KiZlMrnctGfA==@linaro.org X-Google-Smtp-Source: AGHT+IGft3z3XzxslC9EjzwiZL56e5oiBIdOlbbLswx00Y2TGeUPxJKAdDkFU8WW+3JSWJFu7HfU X-Received: by 2002:a05:620a:1a8e:b0:7b1:4579:80fc with SMTP id af79cd13be357-7b331f26ac7mr627526585a.60.1731134589509; Fri, 08 Nov 2024 22:43:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731134589; cv=none; d=google.com; s=arc-20240605; b=O+yWZbRxP245p1cgYZNCb6dCzuktWj+PU4bLRr3TQkgSkhaCggOcSkE7xFBT3lMHS+ Sgi6puOxG9aHUSRopd1hrzgnKG/RgAicbgfzo6D+k0sBoe7g+RHbHYRwr8muM9QYYdH2 T7Axa3dStW8fW5PRc7/LW4gTXFUGWRrYr8kAhipeHCvw5uDoTAIQ40RCWAKNRFd52FAT 2ZamOsF5MAAlm3s6xw5QLsJru1Wjhfyr7SGfwYNlHwugBvEvmePM76bimAWZhJ4sx5hl qWB4ASRy8LtDSm/W7S/CAdcwe5KQ+sWahvUwJEzwj+fxvv18LlcfhRPvNrLwxsm4tGPb iRyA== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=fW3xlArfAu+YmkvscocZkepM8sSJXeunOlMRfvOKqqU=; fh=K4abbxCgZAPvqzOXA+PZ7RIZh+KufMVJze7rXLOwES0=; b=F8TKYfTUuTIjOgDanJQhdIYtuZnM0aitn1PovZkhjxzosxPfbUZQfLzFj+YBG8cEGU DbJK0K4+S1wbq4mjpi6ngEdVjSSw4poqHfDnXmM0Hf8fFj9MOKLk4I+HhwkIho3g24hp W2jPYFLiSLYhTlSd3WdviAmdsxcXiJuoS1WrRt99DJMMMd8yVcFC6BRyHf0Wa8qPD343 LhTf8lJhsZ4QUOJr12aIAQ3e5gGPxMOaltRDPre4GlCm95+HPcXTEA+JwJCWAdxm6rcm tFJj+e+x6sG7pKPD5nHPp6mcZJ+0qN4PT/4c2M5u0laeMcxhGZXS33/a6yLJe0whX+t5 1L0A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7b32acfbe22si612068585a.480.2024.11.08.22.43.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Nov 2024 22:43:09 -0800 (PST) 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; 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" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9f8N-0003Co-PE; Sat, 09 Nov 2024 01:39:47 -0500 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 1t9f8C-00035K-6h; Sat, 09 Nov 2024 01:39:40 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9f87-000208-1P; Sat, 09 Nov 2024 01:39:33 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id C94B2A12EE; Sat, 9 Nov 2024 09:38:09 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 3F71B167DD2; Sat, 9 Nov 2024 09:39:04 +0300 (MSK) Received: (nullmailer pid 3272512 invoked by uid 1000); Sat, 09 Nov 2024 06:39:03 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Tokarev Subject: [Stable-7.2.15 07/33] linux-user: Fix parse_elf_properties GNU0_MAGIC check Date: Sat, 9 Nov 2024 09:38:33 +0300 Message-Id: <20241109063903.3272404-7-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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 From: Richard Henderson 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: Philippe Mathieu-Daudé Reviewed-by: Michael Tokarev (cherry picked from commit 2884596f5f385b5712c356310dd4125a089888a8) Signed-off-by: Michael Tokarev diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 87895847ec..97528a13ed 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2899,11 +2899,11 @@ static bool parse_elf_properties(int image_fd, } /* - * 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 @@ -2913,15 +2913,15 @@ static bool parse_elf_properties(int image_fd, * 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;