From patchwork Wed May 8 17:44:46 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: 795485 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:34e:ceec:bfcd with SMTP id k28csp903037wrc; Wed, 8 May 2024 10:46:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUZbYzQKcFvhbP/XzFNS+FItanNZZ75BkzwEWKktC5gcIYdDpj8CtOVPrR9sKd/gYMOgR/8/SV6J62IcLldZZc+ X-Google-Smtp-Source: AGHT+IGcgareSPoCujO7OR2uQ9k85Ib43rYENt4uUYDCIjGjFYaBJakY7My8PC4mPXYZGV1OgveL X-Received: by 2002:a05:622a:1896:b0:437:7a3f:d392 with SMTP id d75a77b69052e-43dbf850894mr38869621cf.46.1715190396202; Wed, 08 May 2024 10:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715190396; cv=none; d=google.com; s=arc-20160816; b=nhxx80yLxLZBw6WqhzqVsW+/NcyalVgcPTUwA6+Fg5eHxi+N9dAY4ouc/23qR7X+5n CBVVYGBeOzRPnzjr9zP1w7Wr4pnAZ85MWW4hbtfpqNokLzaLul7TbAEXE9MlPyEGobcv 6dsC2g+Szu2CNChnjbIz9t0tZcGv60OuXu5pbNE30D03XnDxj980nH74dBzo+r+M+FPm NAxQisvrZGTLq9geLuZYEZYJrHwOajTdF3R45YueVOtQYk8ZKUlWRKB9/oLgqpBmBUmv fREhpNaf9Zbk+vx86jJQLkTHvk5+HNXhU7lxa7MHPTap+zWiIuvL1VsEXf0+8Cbtwdci gFDg== 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=UIF3u0N5I7QP9EtogOTWS3nnNPFic90FVU2Lm7bwK+4=; fh=8ZOylEp+NpwYftTqS/xtL3OTm6TaSZcnb9sCIRGaSxk=; b=fEjsO8LyuXslcSDk4Mu+Iz/LmChzGsUrLXoYg1TP7a3yKaCGxGkN1eLi6hK/m2WxC7 VGfk6Gga5nsV05oHXmWJKNMUccxNcdq+wIQsgvR9cCT1fw0tSfT4c39ds1cY6n54fDST KkOzZ2LPcpvnoO3A0vEt5rYTq37NYMf8Vlmuf5BMXVIePmwvQoePYL5fnItJ4ay0lLmB hrTxDm2XXjirXNOyuHav0dFUBdzYmBB5VDZUSqCPAwpOogot+zzg7GZaC7ZUhGC1wlT5 i7KQc/dymVt+LXRkkEFIvlb2juOJYv7ug/uy0+j4LUZ+BcNvynLnUHn+AAW/soMha4lg OaUQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hMQCv4M5; 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 14-20020ac8594e000000b0043af8d3965asi14629727qtz.226.2024.05.08.10.46.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 May 2024 10:46:36 -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=hMQCv4M5; 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 1s4lMe-0000O1-OY; Wed, 08 May 2024 13:46:00 -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 1s4lM9-0000KT-0A for qemu-devel@nongnu.org; Wed, 08 May 2024 13:45:30 -0400 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4lM6-0007Ic-EJ for qemu-devel@nongnu.org; Wed, 08 May 2024 13:45:27 -0400 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a59a5f81af4so1227611766b.3 for ; Wed, 08 May 2024 10:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715190324; x=1715795124; 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=UIF3u0N5I7QP9EtogOTWS3nnNPFic90FVU2Lm7bwK+4=; b=hMQCv4M5UWNYSO53L0UIrp4qg+W4zPVRPVXzumcndqPGS65zkcFOv/djRZ0i973XD2 x9d/lf3J51BNNKgL0rCuWSk0RZkwKIn4ilPBqefxKNCxD6VGH6GUPvgwuQch9fM56dSw xqXvaXogCBhA0XzPdBYhodaLcA/fNOgIqNXQHOwtQzj3p3Q9G99t9BfJKKr9+k0P21HI 4jA2voYm59IhBCLs5Z1U3iBf3tUKPJdpyWBsJWPU3aiYOTN1Dxiqjxc8zrMFBfBE3Q8E s8DeMivA63wI8QRIjQ78lng7StlHrsE746Vpgh3qiqgTgWBdFYVNAhKATLHE3xyB8KtR og2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715190324; x=1715795124; 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=UIF3u0N5I7QP9EtogOTWS3nnNPFic90FVU2Lm7bwK+4=; b=YV/vvI4ZLcyQa6W2PDwmAm3C6xN5DylKkyD4kHQagzosjCzPAjRBUNB9oIt9WMbbqP 7CYwNx/E+vEeE3sizjk5kKZp8UaeXQsaDkMuJ88a3oe/h8QLF/poUAgRS8pRdRLR0z0Q FJoqIXcrJpfe89hbd5ippqYVO6Fhwfv9/oz/XCnA310hML7MXzCc7PuqVnSYil98qYpW RMNi9WEV9FcGQuOuRxlNebRpdNmSJKgVFXAp5bfQoZ4lT3vuY89lye6hokoNhohsqIkT swci4WCdfF/HGJzIZdp3niYkwDlN50q2PpnG0OP6+YI8jWJ2tvuzWGIDdP8yLfeMSLPi udRw== X-Gm-Message-State: AOJu0YzocqTRb/a2irAn/vW/kCHhg0K8dUFLZsELCOC+D51xZriHzpyB /8lEzmItQMkkOHz7Fpt0mS+q8Ui7LeBz0rdye/q3N5x8gjQUcIL5OiEg5wpDWao71fFcvEuwlsg J X-Received: by 2002:a17:906:f8c4:b0:a59:bf43:4e40 with SMTP id a640c23a62f3a-a59fb94a651mr225408466b.14.1715190324214; Wed, 08 May 2024 10:45:24 -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 jl24-20020a17090775d800b00a599acaff03sm6667049ejc.19.2024.05.08.10.45.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 08 May 2024 10:45:23 -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 02/26] target/ppc: Replace g_memdup() by g_memdup2() Date: Wed, 8 May 2024 19:44:46 +0200 Message-ID: <20240508174510.60470-3-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::636; envelope-from=philmd@linaro.org; helo=mail-ej1-x636.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-27-philmd@redhat.com> Signed-off-by: Philippe Mathieu-Daudé --- target/ppc/mmu-hash64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c index 5a0d80feda..0966422a55 100644 --- a/target/ppc/mmu-hash64.c +++ b/target/ppc/mmu-hash64.c @@ -1188,7 +1188,7 @@ void ppc_hash64_init(PowerPCCPU *cpu) return; } - cpu->hash64_opts = g_memdup(pcc->hash64_opts, sizeof(*cpu->hash64_opts)); + cpu->hash64_opts = g_memdup2(pcc->hash64_opts, sizeof(*cpu->hash64_opts)); } void ppc_hash64_finalize(PowerPCCPU *cpu)