From patchwork Wed May 8 17:44:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 795488 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:34e:ceec:bfcd with SMTP id k28csp903158wrc; Wed, 8 May 2024 10:46:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWOpeqUYa+Anq0Fpl2/bLDiUf4/Zdu4vs9t1wBMK7576f/UXEc0RA5JNVev2YYaArkb6wA87plQ0Ec05CF7vtev X-Google-Smtp-Source: AGHT+IFtYGKAjakT1onAiTJuPdNbvkPuq+hKb/rqDKCsIUkXw916vB25hCHezPBai7iQw4tRRiRL X-Received: by 2002:ac8:7fd4:0:b0:43a:3505:53d8 with SMTP id d75a77b69052e-43dbec0d5b9mr39711641cf.1.1715190411642; Wed, 08 May 2024 10:46:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715190411; cv=none; d=google.com; s=arc-20160816; b=l/IdKpvHT6XbfSMhPxiL0NJiD8eAZDbh7cpc5BqZ/0aDrT3oNiq4xcRGrMfERIZ/aG WSzY++ttj4FKpgowE5uvJ2TOh08ng/q3F/j4Gxzjwy52VunrURcwjdfdYCeuoOnmRSSS rxO//3CacgEVppXvJ5IlEPgBXt84X3rYvQOMdyCERx1fLiinYfM7vTPYcQxijxqPsDzS iNn1Bv71nNsotAj94u0OtpF4r/mXrImiKwXqet1+wX6qSWRvhs/R6o1uJzTwur9liiHt Lu6URKTl+d6EWNdngvtl+wmlcbBLRJMLy0nwh8380nHe35plixNwleDjPsQpQhYrGwGp Roag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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:dkim-signature; bh=4gAKoZA8GiThrSy3LlK57brDrhpN7s+nDa4hQZ9Yrx4=; fh=ExoCTmbI5idixNbZMdXUNpVA3cokZL04D9+8FikNFJc=; b=Uq03dxpEEmysCSNmeElwROxdl1QUxQlB6z5jcxUfM+Bu50fIPYCWbwAwJHDYIzZ6Rs 4R/yW0Rf2bl+JryrrMXW4EmWWLmOauLy6w0JF7l/P+4GlN6fEiBuzoOF3UkWnAXobb/Y J1ngh7s4dBFuBMMOd89g/ldxwTPnUnD+O5CjDe7diJyVWTJ8Tz0z3YBBQe0/AGHVNjkp hX+BVSmV2kDXsOyhomJEURj2EaInzcHm/nBG/Ni+0h6jOYmP0uuOq0M66omtWp/WpEvc Y4PIkQmpH9fJscO0LpsGdgPnFg6ZkkS+lOCBz0TkAHSDBz2vNiJcV13T32mtBMKo6feh HZeA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xztPN7IB; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f2-20020ac87f02000000b0043abdf0a595si13894837qtk.39.2024.05.08.10.46.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 May 2024 10:46: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=xztPN7IB; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4lNE-0000vx-VZ; Wed, 08 May 2024 13:46:37 -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 1s4lMJ-0000M1-PY for qemu-devel@nongnu.org; Wed, 08 May 2024 13:45:58 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4lMH-0007Kz-W3 for qemu-devel@nongnu.org; Wed, 08 May 2024 13:45:39 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a59d0810f59so2275466b.0 for ; Wed, 08 May 2024 10:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715190335; x=1715795135; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4gAKoZA8GiThrSy3LlK57brDrhpN7s+nDa4hQZ9Yrx4=; b=xztPN7IBBEOzcv7Ko63eivjgOQG1G1yu0sRmVoMvtlFUKRFI5FpaCp0Jw7J9qVrzs0 5RhzrGsOdPbfgAUIa9UR2mFg+WP16d0WexNHB2+sfEQTxZwXZCG7FqEty9Q03qOECkEe TTkJ4++b3amcKaB9xS5cOiaXPWxMAH8ua7JUXhNNGz+qaQwArO3j1NpcIsaa3I36eg5G rWEg6xd223GVnNDTNms69/zrkIUMfs0m/ju8abSXKpolYKSq31PI8WiA8RoQnj5m1rfM picxx6DMWP01QJtG913N7No83csvCId1tzB7Gf25GK7tHhxXv5GsoIbFR+gYqo3DXN8z 5mIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715190335; x=1715795135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4gAKoZA8GiThrSy3LlK57brDrhpN7s+nDa4hQZ9Yrx4=; b=X0GRXjLNIZUUY/PEZUKx0nn2LjfnkFRjb78YfCA3PAJ2HD4nz20KR5t/rGWq8hdTgZ DVtXwfpPEsTxM19dSJ4zdhKHroULOzLw5qTVR0Q/DXtMsmgTabrZFwCHRX4UcjT5jAQZ 8p/r4OZp1vG7184B62YYcozFQcfA8x+NTK1OSdS1dXsQ7gLbzpymTXGXpDk1gvUHYN6G OGlG9Z4xJsEmwqgSZ4sycRcfHSxh03rdIiq2fwf/giuv+urC8V2tsDZWfoyKqnvWeu+J +z48MEDtiNB2fRtFQKsL+f9HcTx4VFF736NYFVmjMEI7LCKdpfYzlX0K9ay2HQGgrCm2 fQvQ== X-Gm-Message-State: AOJu0YycahPWelAaDlyr2396lftFt/ov/XM8iP+umvZi96Sjv/g3RR7D 02qTNW+hoWebT3xYzGjYzCBEObH9YwuZc4KJm4LOG2EdaislyDRxs05Zzu5pXTvhZRiBak+GPsV I X-Received: by 2002:a17:906:368e:b0:a59:c0a6:25d3 with SMTP id a640c23a62f3a-a59fb819d1amr195236366b.12.1715190335302; Wed, 08 May 2024 10:45:35 -0700 (PDT) Received: from m1x-phil.lan (sar95-h02-176-184-10-250.dsl.sta.abo.bbox.fr. [176.184.10.250]) by smtp.gmail.com with ESMTPSA id z7-20020a1709060ac700b00a59a0ddcc3dsm6077937ejf.44.2024.05.08.10.45.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 08 May 2024 10:45:34 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , David Gibson , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PULL 04/26] hw/ppc/spapr_pci: Replace g_memdup() by g_memdup2() Date: Wed, 8 May 2024 19:44:48 +0200 Message-ID: <20240508174510.60470-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240508174510.60470-1-philmd@linaro.org> References: <20240508174510.60470-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=philmd@linaro.org; helo=mail-ej1-x62e.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 From: Philippe Mathieu-Daudé Per https://discourse.gnome.org/t/port-your-module-from-g-memdup-to-g-memdup2-now/5538 The old API took the size of the memory to duplicate as a guint, whereas most memory functions take memory sizes as a gsize. This made it easy to accidentally pass a gsize to g_memdup(). For large values, that would lead to a silent truncation of the size from 64 to 32 bits, and result in a heap area being returned which is significantly smaller than what the caller expects. This can likely be exploited in various modules to cause a heap buffer overflow. Replace g_memdup() by the safer g_memdup2() wrapper. Trivially safe because the argument was directly from sizeof. Signed-off-by: Philippe Mathieu-Daudé Acked-by: David Gibson Message-Id: <20210903174510.751630-17-philmd@redhat.com> Signed-off-by: Philippe Mathieu-Daudé --- hw/ppc/spapr_pci.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 72cfba419a..7cf9904c35 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -2188,10 +2188,9 @@ static int spapr_pci_post_load(void *opaque, int version_id) int i; for (i = 0; i < sphb->msi_devs_num; ++i) { - key = g_memdup(&sphb->msi_devs[i].key, - sizeof(sphb->msi_devs[i].key)); - value = g_memdup(&sphb->msi_devs[i].value, - sizeof(sphb->msi_devs[i].value)); + key = g_memdup2(&sphb->msi_devs[i].key, sizeof(sphb->msi_devs[i].key)); + value = g_memdup2(&sphb->msi_devs[i].value, + sizeof(sphb->msi_devs[i].value)); g_hash_table_insert(sphb->msi, key, value); } g_free(sphb->msi_devs);