From patchwork Wed Jul 1 13:13:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Purdie X-Patchwork-Id: 91505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDBC9C43327 for ; Wed, 1 Jul 2026 13:13:42 +0000 (UTC) Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.44824.1782911620737753245 for ; Wed, 01 Jul 2026 06:13:41 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=OA8PZsvu; spf=pass (domain: linuxfoundation.org, ip: 209.85.221.41, mailfrom: richard.purdie@linuxfoundation.org) Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-4720d22c94aso586352f8f.1 for ; Wed, 01 Jul 2026 06:13:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1782911619; x=1783516419; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=VMgfiNjmVYo0V29h5q5zEZ5lmJeIMhlBiAJvtttDOpo=; b=OA8PZsvudZ93Tv3r0hcI0o0/9x14o1DyZLPnAqHFmGywIiMexhu1IqqQPkOK4h04R7 8ocrjg67zPk88E0aubR0i6L1lApHj7bBI5mZXQY+OkeQEs9kMWIJ4IKCAclQo45kb03j /TWl33TNuKM/7iGDCYqzRTaAasl6kqYP2HCss= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782911619; x=1783516419; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=VMgfiNjmVYo0V29h5q5zEZ5lmJeIMhlBiAJvtttDOpo=; b=n4jIxmPVSj3F5/b5adRN9d913USE4OAjlH5BeL7Va36LTWJj5SVMcooM5wjL8J4p0U JmfXEwbO7bshTVgj77mDmDRSP7vD2pLlFtBtpArawIucPvYqfcBhK6NrOatttwJVswmc 5x7bUeai3u91QhuLGoxeIO+tjHjvYq2co/mJIPf2QdE4cMjPcUM1PSA2YH8+G8Ny32dz 33lgLT3Wbkr/oqlMcUcSXK0uloD1hh9OP1vVJpQlOa44cOKODGfTRjmk4xjl7Tn7Rtbw iTxaesmuSoyTXDXYrJf8CBRzPo99Ty0zQ1qJThJSfDsTXSpP4XHuAk2HSfaEIcgMb0zh S2Ng== X-Gm-Message-State: AOJu0YypOj68DZxyxwN9EcSBPP3NUSr3tHv3hnB5/u1xdx3jmPrrl95T MTqAcBC+2ZkeHSgilF9yi21u+IrJQsVr4kc+JEf1GniLuo1Y2pZRoQcMFP6p5izLYG2kImYrso/ QWxSZ X-Gm-Gg: AfdE7clKBelYHyItIJwoJb8evgI/VhYxava/adeeMWWBxorRYiUIRvP2VQtMR8ozuSa DUMgTZ5Kg6Wnvkm5FmXxEPjQDMtFmpzvGNKYh9Ox3cGC7kbhK/NTskzLydnAuBaF/WFuJ2ijot3 awk0zH42B37OmHVOMcjWbQosg13jvm0qnCnqnN8C2z5FdBvcYGPvGBRabBsZZBDu54iWf5KUDPZ Qk616hkR/xxB/suQ/KXFQ82OkimoDyb2XEo6f2ctSaF8x5WXy3lPvjyfBcelzga+Oct6V1XP6Hh hXevLhh9kRD1rCl4M6xLM7tMJT9A428/dRv0qswD7V77xvmguqC0Q7vX++VMyMYpUIfmC+LTFWs o+uDpgKD4FpeMSz5G5VtXE7JwDERevHcfeWDb73k/zrVw39vRKIQ9d00/Cf+hOPn9JS28P+h810 zbHrNcAkGkCWkXIdMFYEp/Iniz/UdEwm3SR5qJvjkGBQ== X-Received: by 2002:adf:e006:0:20b0:473:1ccc:15be with SMTP id ffacd0b85a97d-477b11002f4mr657060f8f.39.1782911618572; Wed, 01 Jul 2026 06:13:38 -0700 (PDT) Received: from max.int.rpsys.net ([2001:8b0:aba:5f3c:6b3f:20f2:ee05:f032]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47567884770sm17568280f8f.33.2026.07.01.06.13.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 06:13:37 -0700 (PDT) From: Richard Purdie To: yocto-patches@lists.yoctoproject.org Cc: seebs@seebs.net, mark.hatle@kernel.crashing.org Subject: [pseudo] [PATCH 1/7] pseudo.h: Avoid accessing unallocated memory Date: Wed, 1 Jul 2026 14:13:30 +0100 Message-ID: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 01 Jul 2026 13:13:42 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/4343 We can call STARTSWITH in cases where the item being searched for is longer than the string itself. Switch from memcmp to strncmp to avoid accessing unassigned memory. Signed-off-by: Richard Purdie --- pseudo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pseudo.h b/pseudo.h index b6c13f2..1152c19 100644 --- a/pseudo.h +++ b/pseudo.h @@ -99,7 +99,7 @@ extern char *pseudo_version; #define PSEUDO_LIBDIR "lib" #endif -#define STARTSWITH(x, y) (!memcmp((x), (y), sizeof(y) - 1)) +#define STARTSWITH(x, y) (strncmp(y, x, strlen(y)) == 0) #ifndef PSEUDO_LOCALSTATEDIR #define PSEUDO_LOCALSTATEDIR "var/pseudo" From patchwork Wed Jul 1 13:13:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Purdie X-Patchwork-Id: 91506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1748C43458 for ; Wed, 1 Jul 2026 13:13:42 +0000 (UTC) Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.44825.1782911621353107219 for ; Wed, 01 Jul 2026 06:13:41 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=AVlUbanw; spf=pass (domain: linuxfoundation.org, ip: 209.85.221.42, mailfrom: richard.purdie@linuxfoundation.org) Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-472055b0efaso413194f8f.2 for ; Wed, 01 Jul 2026 06:13:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1782911619; x=1783516419; darn=lists.yoctoproject.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=CkUWwxUNRvxsnC+n183QLGxO6VkJqiffdg6soptPVHM=; b=AVlUbanwdG+QpiteIQLhVQhtmDZnRN0pKnyauGlYGPWJGBZR+aUAPymM/92XBTNkIs t4tNPbv2uxwXy30Xy8rG7KUrtKGxZ+baBdHbPcohkZ0I+jyhkX6Iwdxik4ZBAh59fRAE KAhp/S3m7WR2OtVG4QtmWZ/3l4EqnaCE5Kftk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782911619; x=1783516419; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=CkUWwxUNRvxsnC+n183QLGxO6VkJqiffdg6soptPVHM=; b=orQ/lpTGDOPdjH6cQHrPx8ft93oxnULDVIEyHHlj1ByjV4qowjb9AZZJYIA+p9sN/+ E+CZk3KFGQf/Vs/zNi3JCzrXhihGHZ0cbzU5Dd33UajKCEcdD4ABWkTfF92PdGlzTfcu QsAs0HfxtwvETf5LUSvqRfSjLjYyzUjm6JUlMZgRYysraOME27eTOYUS+7uWsuKxflBM pXxedHCxx2a2sHVgO428P0bl5eap7xZl3qVlLLa6JMKeayldpO2NFxrehfOd/YDRbRHJ JIaT7Q0F1dwGt3OZzxBuZVIH7XXxeXZga6839QxswaIrbso5TW32VLlTwJ+Ko7FtzCZ5 l2tw== X-Gm-Message-State: AOJu0YwGINE1R+Fk9FU2xGdpXjGoVcfo8IW0UPUhkEfGL6IPAXq8HJft xRhifoLI3XByC73BjunufQL8QpQN+dx5kGeX8LxI8FK9Eo2ToBf0XYKW9of2jGTJQNZtVvuHtG/ mYbxQ X-Gm-Gg: AfdE7cn1++hWkj0+YC4Gx7BEz9CzswMe9AMqsqhFEqnTe8JFUgw09cqpNM+jM7LEsv1 FY3R1aAQUteRphHLAqhkYlbc3Vkh1mxHX+Mu4H1Ynobn44g9ldVuhO/9SKfNEEHOapGMlbdbrMb szo2Bk4SwRH9NnP8y8++/L9bCVHw+A3wsCu2ouqunC1Viu6psqX0SBc1VpHBf0l6Qiaq95Sf5mQ iP9p0aYmViw6QSLCBtJ5zswGxA73viLndMi8dui+H2rLd5L8q5OehiDIOmk2FQuKsVzcAuqOr/4 jj2/5JFB6p4HeS/4442gRbnfj++hsTjnCBDPnqySM5BR0h3ES1ebK/WPDfL6QOgzJoIYJPtIRez bHJJ9al45HiFjY+6MFbIyQEckInbv3rFsG0V+8Zye6Sdrw5775xj1/QmhHwmf82JhZD+QIUrHCX PHN6CiEbqYUiLENd1tk1swYJp2dbR76Y2Fxzzp2hE6Vw== X-Received: by 2002:a05:6000:1847:b0:475:e3fe:8ac3 with SMTP id ffacd0b85a97d-477574b037dmr2864476f8f.8.1782911619574; Wed, 01 Jul 2026 06:13:39 -0700 (PDT) Received: from max.int.rpsys.net ([2001:8b0:aba:5f3c:6b3f:20f2:ee05:f032]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47567884770sm17568280f8f.33.2026.07.01.06.13.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 06:13:39 -0700 (PDT) From: Richard Purdie To: yocto-patches@lists.yoctoproject.org Cc: seebs@seebs.net, mark.hatle@kernel.crashing.org Subject: [pseudo] [PATCH 2/7] pseudo_util: Avoid accidental free calls for without_libpseudo() Date: Wed, 1 Jul 2026 14:13:31 +0100 Message-ID: <20260701131336.3578279-2-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> References: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 01 Jul 2026 13:13:42 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/4344 We need to return list after the strdup otherwise the caller doesn't know whether to free the return value or not. Signed-off-by: Richard Purdie --- pseudo_util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pseudo_util.c b/pseudo_util.c index 2b0cc04..9cafad6 100644 --- a/pseudo_util.c +++ b/pseudo_util.c @@ -336,13 +336,13 @@ without_libpseudo(char *list) { if (list[0] == '=' || list[0] == PSEUDO_LINKPATH_SEPARATOR[0]) skip_start = 1; - if ((*real_regexec)(&libpseudo_regex, list, 1, pmatch, 0)) { - return list; - } list = strdup(list); if (!list) { pseudo_diag("Couldn't allocate memory to remove libpseudo from environment.\n"); } + if ((*real_regexec)(&libpseudo_regex, list, 1, pmatch, 0)) { + return list; + } while (list && !(*real_regexec)(&libpseudo_regex, list, 1, pmatch, 0)) { char *start = list + pmatch[0].rm_so; char *end = list + pmatch[0].rm_eo; From patchwork Wed Jul 1 13:13:32 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Purdie X-Patchwork-Id: 91509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7241C43602 for ; Wed, 1 Jul 2026 13:13:52 +0000 (UTC) Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.44674.1782911622353582554 for ; Wed, 01 Jul 2026 06:13:42 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=DB6/NX9A; spf=pass (domain: linuxfoundation.org, ip: 209.85.221.44, mailfrom: richard.purdie@linuxfoundation.org) Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-4759b4f0897so497029f8f.1 for ; Wed, 01 Jul 2026 06:13:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1782911620; x=1783516420; darn=lists.yoctoproject.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=H+U3eiOeCr2g65PDVF8GsNmdiKfsmjw8wbsM8L7dweA=; b=DB6/NX9AD5gLp9tY2iT8paxGulPYrgBak0qgQeetwTLpsG9qm0mISVgnb4g5YbfGrv rA+OgAYSx3VR8gO2NRiCExF13KDuLb7FuenqNCNTni/DKeyPOARD4nFihcdOJJxoMqZb CIm5r5vMcdgCKxGydMXv1chSYfLh0F5hyWl24= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782911620; x=1783516420; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=H+U3eiOeCr2g65PDVF8GsNmdiKfsmjw8wbsM8L7dweA=; b=papx9HV1sekvX5h8u5nttlvx8L61tZBVzj0bCsqg/aAEMq02RS/PsLejG0b4Mc5Fwj 5cnUVDhboC1rbfzgswKdkIGq2qY/sGSo0RBhHY3fx3FtBoQGPRxcLa0yipaxwTQsgtpM JXEAKydwtVEFPCosKhIh+w1E6P3OJIbDZge1+m49wfvgNIRCtmWStpJx/IhEWrQR/2tj N19rS+/+IbGnHUooUh2a7oP1+ZyD+PMcI9SmWOUkheQ60e/undjNgGGHvGTDoEge3CG9 rElrpLwzNL0IjzIF8TdXPOM/SSkaENP8GoDkgNRo5jW7qYe2QD1obj7Md79jw8xUusCI rlvg== X-Gm-Message-State: AOJu0YxuoSWdrybXOcmKNow+I4A1zAmCU9y3M82ulRIz9AqRAbteg6fZ 7ejXAdY9wy5mGR+J386cTm1kQWEOq2Dt5yIBSMZYnVZfXvJVhwPJR6kLQf/GZnzHigBeOSP8ltS AuaUW X-Gm-Gg: AfdE7cmWC60eLVs2jtYeKiFcJuNbucJWMb3GMXSEYUocnLdKOZpI/QQ0iM3mn1235jY B6n8m1IY0nRqZmrBO+hxT2osLlqh7LnXQYyWXvMRhpdrreH98eq/xmXbttXdgC//+7QNWfTRYLt 5aJkmi12v4cIgCFp8Kt2e2Tf72KdzbU7zGR8A2caDLveOkOQgNjlVGLIUYo2Bs2qhpyw2eUw6+4 Xbh4aD0/Z0hn5T201czrcEFiggIyEZ7jRZCFPAU0utgF4YKTHXwnH6RLChXSr2DZRBiHVwOquB7 45UghLl7SMIX3wOc7ML+PGajllF/R2K3ML4ctHt5v8YmDdOC8jolmMo+1qEDxj+U9wepfxr/y3w bXyfOqRP58FDqvrcHYNdxTCuyMTT2pByRiS2xQQ0fstM/6Hlf78rNQejNQoR9sy66SVeHQpZkPf +vd3YX9PHwEAxQKtkesNYAAHT/G8Qysu3+t0GbbcAnPQ== X-Received: by 2002:a05:6000:18a7:b0:474:d7a5:4b6d with SMTP id ffacd0b85a97d-477b38897b8mr762972f8f.21.1782911620531; Wed, 01 Jul 2026 06:13:40 -0700 (PDT) Received: from max.int.rpsys.net ([2001:8b0:aba:5f3c:6b3f:20f2:ee05:f032]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47567884770sm17568280f8f.33.2026.07.01.06.13.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 06:13:39 -0700 (PDT) From: Richard Purdie To: yocto-patches@lists.yoctoproject.org Cc: seebs@seebs.net, mark.hatle@kernel.crashing.org Subject: [pseudo] [PATCH 3/7] pseudo_util: Ensure pseudo_setupenvp handles memory consistently Date: Wed, 1 Jul 2026 14:13:32 +0100 Message-ID: <20260701131336.3578279-3-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> References: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 01 Jul 2026 13:13:52 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/4345 Most of the new environment values added to the new environment array returned by setupenvp are already freshly allocated memory. Ensure all the returned values are so the data can be handled consistently and correctly freed (for a later patch). Signed-off-by: Richard Purdie --- pseudo_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pseudo_util.c b/pseudo_util.c index 9cafad6..126746f 100644 --- a/pseudo_util.c +++ b/pseudo_util.c @@ -1197,7 +1197,7 @@ pseudo_setupenvp(char * const *envp) { } } else { /* keep old value */ - new_envp[j++] = ld_library_path; + new_envp[j++] = strdup(ld_library_path); } if (ld_preload) { @@ -1228,7 +1228,7 @@ pseudo_setupenvp(char * const *envp) { for (i = 0; envp && envp[i]; ++i) { if (STARTSWITH(envp[i], PRELINK_LIBRARIES "=")) continue; if (STARTSWITH(envp[i], PRELINK_PATH "=")) continue; - new_envp[j++] = envp[i]; + new_envp[j++] = strdup(envp[i]); } for (i = 0; pseudo_env[i].key; i++) { From patchwork Wed Jul 1 13:13:33 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Purdie X-Patchwork-Id: 91507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8FDAC43458 for ; Wed, 1 Jul 2026 13:13:52 +0000 (UTC) Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.44675.1782911623369440769 for ; Wed, 01 Jul 2026 06:13:43 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=HADKotyZ; spf=pass (domain: linuxfoundation.org, ip: 209.85.128.42, mailfrom: richard.purdie@linuxfoundation.org) Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4926bd21aa1so4087985e9.3 for ; Wed, 01 Jul 2026 06:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1782911621; x=1783516421; darn=lists.yoctoproject.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=XRyT7VxF6JnWAf2ODdelGILCLECir/PuCBUMYYiWxeo=; b=HADKotyZODEZ0roXuaAfimYvjMU40QQAtH0VZlrOT+FlzKsjBxkqt5+PGUo4HR4Q3L Zo5XLSXuAa8Ypp5ZSLU/nxDLuap9PvcLKID+j1jLhjVd5FH3dIeFP9GSPOP4C4rndkzn dtBpmiINhhxIGM+vu0hs1o7fRor/RPBOw8ZJs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782911621; x=1783516421; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=XRyT7VxF6JnWAf2ODdelGILCLECir/PuCBUMYYiWxeo=; b=O2D4dlM7fxJ/HGLeaHmRukOmlXYD3k1NjrlCNF7KXWzYIUvrF5+Y9r2/nzxZJaRVBw s1Ot3L/xoHgjFkQX0y2eK8IQjyR8NS9tsnq5eZRdwIN2I7nvMk1DGftqtMoXCPdcgKnb 2TUQP9eKfCfSrzgdDLpg02toDXPxSiR04BT5mc974igZ26FjffDzP10HKcI3P+MXEoEx MJpN5j69uzBIZJ3nxGRMmqV8iUGRQW+WfiDsXG9wTUmYwx7NGJ4kInyWouyA5mvbLXcs RdiPyn5J5LBYMhKyZa7w6SeCngJcbb+Kky+p6yB0Fj86Wbt+lOtheVlW7J6S6STTb3dg c7RQ== X-Gm-Message-State: AOJu0YxGUi/FM41N2yi2+hFzZnLCtu5v1m/davGnETI1ptm+sz5pp+iA AIvStsOWYbm6pFw1NQWPq8fS96kLHFxHaAmfWCSdVgNsuw9AhBL2nP2Gn44K5yS8d1HME8R+Tmg ZbkDL X-Gm-Gg: AfdE7cnxc/hTkWYvY9ZKlF1PGNvnyzPI85dRDj089fNvdL949HdkpMnemjIvpbZ8buU 4cerbUIlFpTXvMpb+NV1Abw61R5ZOoFhy1QdScQzCkdZwdJwjVnl4H2Lw7XYvCqOefS+kku5eY2 z+/NEUvU2EF+HAi12O9RMwGImR7/mifdedVt76MWQPKUP+5i5+ODrjx1Ne9aujR7t6gUukeFeM8 ldKZg8W6rOIu1TKnJaXj1H3EwqbuQ1xpfiLj5u6WmBG4OnP7C098Prja6sc3qcdnByttCEg0jrD xAILIFGHEBIr4Uc0aFn1Tb5rDsFq0ouY5N1aQYAiX8IZVC3KErv2OuHvxvPUz4dMZZUtisvVyOE eKPgxBOumX+kgVCQiXsc1wfB77qLIWKuoNYZYHh449qiqSDprGggJ6s6KQz1vwdZcDdONSr5Vr9 DsZethbfkrqCuGlj0OChzLQD9l7MX2RZG3rmD/raaClg== X-Received: by 2002:a05:600c:8715:b0:493:bed7:6d7c with SMTP id 5b1f17b1804b1-493c2b8943dmr23653255e9.25.1782911621517; Wed, 01 Jul 2026 06:13:41 -0700 (PDT) Received: from max.int.rpsys.net ([2001:8b0:aba:5f3c:6b3f:20f2:ee05:f032]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47567884770sm17568280f8f.33.2026.07.01.06.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 06:13:40 -0700 (PDT) From: Richard Purdie To: yocto-patches@lists.yoctoproject.org Cc: seebs@seebs.net, mark.hatle@kernel.crashing.org Subject: [pseudo] [PATCH 4/7] pseudo_util: Avoid a memory leak in pseudo_dropenv() Date: Wed, 1 Jul 2026 14:13:33 +0100 Message-ID: <20260701131336.3578279-4-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> References: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 01 Jul 2026 13:13:52 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/4346 Signed-off-by: Richard Purdie --- pseudo_util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/pseudo_util.c b/pseudo_util.c index 126746f..5e77977 100644 --- a/pseudo_util.c +++ b/pseudo_util.c @@ -1000,6 +1000,7 @@ void pseudo_dropenv() { } else { SETENV(PRELINK_LIBRARIES, "", 1); } + free(ld_preload); } } From patchwork Wed Jul 1 13:13:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Purdie X-Patchwork-Id: 91511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAF3FC44500 for ; Wed, 1 Jul 2026 13:13:52 +0000 (UTC) Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.44827.1782911624508925392 for ; Wed, 01 Jul 2026 06:13:44 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=P8u8YDC8; spf=pass (domain: linuxfoundation.org, ip: 209.85.128.42, mailfrom: richard.purdie@linuxfoundation.org) Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-493b1710405so3475445e9.2 for ; Wed, 01 Jul 2026 06:13:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1782911623; x=1783516423; darn=lists.yoctoproject.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=0IpM5ZuLgfex/2/vmLYQ/z+u91sK8SAoQNKJCZbGnbM=; b=P8u8YDC8xcSSS3uZy0EJ1M09EBCjtu/KpKctkHR9qd1XjEETP8pby8XXrQg5Dj7g4D q3f9NLZVEqLi4PHj7J2d1PEU47pPH9V+QGrEPlZAtDKJ+TnY7acsVpDdDHtcXFo1eCNG j+P1XQVNTHXvPy/BeM1djl8NZZ+hgz3C5WDhY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782911623; x=1783516423; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0IpM5ZuLgfex/2/vmLYQ/z+u91sK8SAoQNKJCZbGnbM=; b=I2SjqtgAHsa2mi2l9VOXTBr3r5t4BjmULyYjBlaF6TSOfC/EnSlXHh9JsmNY/8tebp ZWFEWsvhXTbnesziEZCEJGFz/I8FZ/tRoTGxVORZMlbGJC2KYu9zaIQDGNnT6OwAD8tz p3vgduWVarihpicaFozMZ9djKiKhlB/AVTSpBLzTxP3wirDMShjnO4EYMQkW278JZq4+ UY4H0vJdmeJDZRq5e4cudC9Vz9EClN5Z5Fu9lN5g+mv3Rkrmn5tWNFn0v+lklmg/Zi3S aVlec4tji31/e1KJ+r7d5aMst5Ev6nUy5mqL+ePiDm9uqukYGC3FnncW0MTXeeL+3Ly0 UJ3w== X-Gm-Message-State: AOJu0YzYP3yP+c3HlUiPFejQNGIGJr8re7AIsX4c6MYmPvHUaAQnW//M b5pQ6CZXiXhtmouksKDzuB4yNZAWaqnjfmSU+XHpeW7MAS6Uagf2YfYxu016UNoID8tYIpcJ+kc 40EZ2 X-Gm-Gg: AfdE7ckoPLuS/QK4MPSsO7o+29c5BrQfsM+OiSJOZes/bqoelYOiLkshcbt+9dcsYHG 9sdgRRyMe65CNtOyv7zv6uugwQwvRHSjQAc/OF0OZK3ZOInPQgGtWUrSEzLC1XqevxhwEm0jL0Z vzJ0tE60e5Wh1zKQN3n0kh3gWCriukimM5IAg6USpFtifQJDIH7xZmQK47T0lPPU30ex8cG61F6 1AssW1EaLTJXWX3Qi/QErtEusO9Thae2ZF1J00OyTk32whbC56hnhdw4A28IXdrwIfbVEo1GZnI 0laGi5M4pUYAolg5gK6Ze+pvPKzLOO112wbpFUZr0hm/2w4YbugBchywzMS8UTaKLdRPml71hKL eohw9Nq/gZM3jZ9jbjFTnxfTcDutWPPo0BerqAXqTgxFgFpC5N90h3stwbpGGow7ketFulgbH2w N0NYZplMlDJ8FisglT5SXGbbKdZDmlmI6oGYF2q8m26Q== X-Received: by 2002:a05:600d:c:b0:493:aa28:38ad with SMTP id 5b1f17b1804b1-493c2b4442emr20131315e9.10.1782911622729; Wed, 01 Jul 2026 06:13:42 -0700 (PDT) Received: from max.int.rpsys.net ([2001:8b0:aba:5f3c:6b3f:20f2:ee05:f032]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47567884770sm17568280f8f.33.2026.07.01.06.13.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 06:13:41 -0700 (PDT) From: Richard Purdie To: yocto-patches@lists.yoctoproject.org Cc: seebs@seebs.net, mark.hatle@kernel.crashing.org Subject: [pseudo] [PATCH 5/7] pseudo_util: Clean up memory handling for setupenvp results Date: Wed, 1 Jul 2026 14:13:34 +0100 Message-ID: <20260701131336.3578279-5-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> References: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 01 Jul 2026 13:13:52 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/4347 Currently, the environment array allocated by pseudo_setupenvp is never freed. Fix this (and the copy created by dropenvp). Signed-off-by: Richard Purdie --- ports/common/guts/execve.c | 4 +++- ports/common/guts/posix_spawn.c | 4 +++- ports/common/guts/posix_spawnp.c | 4 +++- pseudo.h | 2 +- pseudo_util.c | 3 ++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ports/common/guts/execve.c b/ports/common/guts/execve.c index 1144f7c..c2be66e 100644 --- a/ports/common/guts/execve.c +++ b/ports/common/guts/execve.c @@ -8,7 +8,7 @@ * wrap_execve(const char *file, char *const *argv, char *const *envp) { * int rc = -1; */ - char * const *new_environ; + char **new_environ; /* note: we don't canonicalize this, because we are intentionally * NOT redirecting execs into the chroot environment. If you try * to execute /bin/sh, you get the actual /bin/sh, not @@ -30,6 +30,8 @@ sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL); rc = real_execve(file, argv, new_environ); + free(new_environ); + /* return rc; * } */ diff --git a/ports/common/guts/posix_spawn.c b/ports/common/guts/posix_spawn.c index e15e68f..5896893 100644 --- a/ports/common/guts/posix_spawn.c +++ b/ports/common/guts/posix_spawn.c @@ -7,7 +7,7 @@ * wrap_posix_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const *argv, char *const *envp) { * int rc = -1; */ - char * const *new_environ; + char **new_environ; /* note: we don't canonicalize this, because we are intentionally * NOT redirecting execs into the chroot environment. If you try * to execute /bin/sh, you get the actual /bin/sh, not @@ -29,6 +29,8 @@ sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL); rc = real_posix_spawn(pid, path, file_actions, attrp, argv, new_environ); + free(new_environ); + /* return rc; * } */ diff --git a/ports/common/guts/posix_spawnp.c b/ports/common/guts/posix_spawnp.c index b2e1fc8..f3dc16b 100644 --- a/ports/common/guts/posix_spawnp.c +++ b/ports/common/guts/posix_spawnp.c @@ -7,7 +7,7 @@ * wrap_posix_spawnp(pid_t *pid, const char *file, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const *argv, char *const *envp) { * int rc = -1; */ - char * const *new_environ; + char **new_environ; /* note: we don't canonicalize this, because we are intentionally * NOT redirecting execs into the chroot environment. If you try * to execute /bin/sh, you get the actual /bin/sh, not @@ -29,6 +29,8 @@ sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL); rc = real_posix_spawnp(pid, file, file_actions, attrp, argv, new_environ); + free(new_environ); + /* return rc; * } */ diff --git a/pseudo.h b/pseudo.h index 1152c19..a2d402c 100644 --- a/pseudo.h +++ b/pseudo.h @@ -66,7 +66,7 @@ void pseudo_new_pid(void); #define PSEUDO_MAX_LINK_RECURSION 16 extern char *pseudo_fix_path(const char *, const char *, size_t, size_t, size_t *, int); extern void pseudo_dropenv(void); -extern char **pseudo_dropenvp(char * const *); +extern char **pseudo_dropenvp(char **); extern void pseudo_setupenv(void); extern char **pseudo_setupenvp(char * const *); extern char *pseudo_prefix_path(char *); diff --git a/pseudo_util.c b/pseudo_util.c index 5e77977..599cf31 100644 --- a/pseudo_util.c +++ b/pseudo_util.c @@ -1005,7 +1005,7 @@ void pseudo_dropenv() { } char ** -pseudo_dropenvp(char * const *envp) { +pseudo_dropenvp(char **envp) { char **new_envp; int i, j; @@ -1036,6 +1036,7 @@ pseudo_dropenvp(char * const *envp) { } } new_envp[j++] = NULL; + free(envp); return new_envp; } From patchwork Wed Jul 1 13:13:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Purdie X-Patchwork-Id: 91508 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C40EBC43327 for ; Wed, 1 Jul 2026 13:13:52 +0000 (UTC) Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.44828.1782911625653500858 for ; Wed, 01 Jul 2026 06:13:45 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=C6dn8QbB; spf=pass (domain: linuxfoundation.org, ip: 209.85.128.51, mailfrom: richard.purdie@linuxfoundation.org) Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4921eed3fa2so4345575e9.0 for ; Wed, 01 Jul 2026 06:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1782911624; x=1783516424; darn=lists.yoctoproject.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=uXE42ppu7GRuoze4l58IbKdiNoH1rvI2YwbnwK/knp8=; b=C6dn8QbBs+cjD+p9GL+uq2jodWPhvoC9fOI/BecnH/iXt7UDxqauEFWum9XhUzYviY kEI3LbDhZT+UBjvrS/aD0ez7sBmBgboNeZYymrrnb3/0/Bods/dN9ij5dNVf54fAWYn/ Sg60RI68wX871yWDvxTtw3ZPvtQC4XrkQWzWk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782911624; x=1783516424; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uXE42ppu7GRuoze4l58IbKdiNoH1rvI2YwbnwK/knp8=; b=Y6OJ4j7Q/wy7EyXc/txrctCgNTPXmGspgaYEIrYU6yyDKxLL9gEDLXD6xe0ehNGhH6 WFCg01sJl9Pq0DugEpY/Azv8h89nuiWu5MbuGtzsksHRVLu6YFBQLEQ1/legTJ20HbtM yi24HTkWGKWZqnkKRkUFqrhTif3mvGumdngvwAtPhXsHEVDuRWDCvpo35I6SelK7SZKE HZcdEkhy4507qMoEMIlSIxtM/hsg3EcN3B2LKyWNAIOkYbmUPNbs5VppbrdHWPL4BM2+ NK0WdTvDuuz+4Dlqh9f103Q95f2b0lA3F5zXEXbK+ko048AHVb3dt9p8L1dj5PolxImG Pcvw== X-Gm-Message-State: AOJu0YwabG+wEV8fOgvDnkPmOsfVej5tMsbL/f0fTOfC0qvu/Cpe7DEZ U7l+lwBbiEV15fj80WKKMUMMopT0cjA+Os3wsOilEf6CorSIs75oXRTvAidGg6tjM6eIdNUqrzT TeuIG X-Gm-Gg: AfdE7cndrMco49GZHXwujfuA2jZGcy2m/NfkzY7UGRJyD0IiMgS36BdJ24d6ASqno1I dReqQxVsgf8VFmQPNa0W+O40ESW30FuQlnG38LPwNw72l3KQ8BJUQzaiceGclKuX94VeIwcFHoH aIeN+Sda4ELFMkyH6OyNaYjKOa+OQQ3dORdU5koKJTYcJIDtqSpRLySh1keMQ6jeA15lSEMCBfk 12Ns5Imfi5oHao9N5ywT1IjwhvssuxKZPh2iOxiBfR5DzWpWk925FinKh51Pfchq2IyX0TmWhSU 7TXWL2MaYGzszgjoQcymMOTAR5dnsiClj3aeKS1Kgs8j+wCC45q05/VlVMdypDDZnmexVdWojRw 8XCEMeorDZXUtsLLpDJbRTQYyCy1pyiLF5d7RfMrJJqTmbWuqxa5g/e26K2keQrIOjMn/KL2O5E aFsC7cAfxfttpjOTf30LvyFGx4Nb4l5NRTsSirkN4q4w== X-Received: by 2002:a05:600c:35d0:b0:493:c3cb:409e with SMTP id 5b1f17b1804b1-493c3cb42d9mr11219835e9.15.1782911623800; Wed, 01 Jul 2026 06:13:43 -0700 (PDT) Received: from max.int.rpsys.net ([2001:8b0:aba:5f3c:6b3f:20f2:ee05:f032]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47567884770sm17568280f8f.33.2026.07.01.06.13.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 06:13:43 -0700 (PDT) From: Richard Purdie To: yocto-patches@lists.yoctoproject.org Cc: seebs@seebs.net, mark.hatle@kernel.crashing.org Subject: [pseudo] [PATCH 6/7] exec*: Replace bash workaround to avoid memory corruption Date: Wed, 1 Jul 2026 14:13:35 +0100 Message-ID: <20260701131336.3578279-6-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> References: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 01 Jul 2026 13:13:52 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/4348 Bash intercepts getenv/setenv/unsetenv and does magic with it internally. The data pointed to by environ may not be allocated by glibc but by bash and the glibc env functions have their own memory handling outside of malloc. Unfortuantely bash doesn't keep environ and the result of setenv/getenv/unsetenv in sync either. This means the current workaround badly corrupts memory and it is just luck we're not breaking more often than the occasional opkg-build segfaults we've been seeing. Fixing this is tricky, the best we can probably do is to read through environ and create our own copy of the it, modifying it how we need to keep the pseudo variables correct. We do already have a function which can copyn and modify the environment, we can therefore swap some setupenv calls for setupenvp and switch out environ around the exec calls. Signed-off-by: Richard Purdie --- ports/common/guts/execv.c | 19 ++++++++++++++----- ports/common/guts/execvp.c | 15 ++++++++++++--- ports/unix/guts/popen.c | 16 +++++++++++++--- ports/unix/guts/system.c | 16 +++++++++++++--- pseudo_client.h | 3 --- pseudo_util.c | 12 +++--------- pseudo_wrappers.c | 6 ------ 7 files changed, 55 insertions(+), 32 deletions(-) diff --git a/ports/common/guts/execv.c b/ports/common/guts/execv.c index 7819911..eb328ed 100644 --- a/ports/common/guts/execv.c +++ b/ports/common/guts/execv.c @@ -8,6 +8,8 @@ * wrap_execv(const char *file, char *const *argv) { * int rc = -1; */ + char **new_environ, **orig_environ; + /* note: we don't canonicalize this, because we are intentionally * NOT redirecting execs into the chroot environment. If you try * to execute /bin/sh, you get the actual /bin/sh, not @@ -19,17 +21,24 @@ pseudo_client_op(OP_EXEC, PSA_EXEC, -1, -1, path_guess, 0); } - pseudo_setupenv(); - if (pseudo_has_unload(NULL)) { - /* and here we attach */ - pseudo_dropenv(); - } + /* Due to bash intercepting setenv/getenv/unsetenv and changing environ + internally itself at will, we create our own environ copy at process + creation based on it to ensure it is correct */ + orig_environ = environ; + new_environ = pseudo_setupenvp(environ); + if (pseudo_has_unload(new_environ)) + new_environ = pseudo_dropenvp(new_environ); + environ = new_environ; + /* if exec() fails, we may end up taking signals unexpectedly... * not much we can do about that. */ sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL); rc = real_execv(file, argv); + environ = orig_environ; + free(new_environ); + /* return rc; * } */ diff --git a/ports/common/guts/execvp.c b/ports/common/guts/execvp.c index acc9fdc..177e4ee 100644 --- a/ports/common/guts/execvp.c +++ b/ports/common/guts/execvp.c @@ -8,6 +8,7 @@ * wrap_execvp(const char *file, char *const *argv) { * int rc = -1; */ + char **new_environ, **orig_environ; /* note: we don't canonicalize this, because we are intentionally * NOT redirecting execs into the chroot environment. If you try @@ -20,9 +21,14 @@ pseudo_client_op(OP_EXEC, PSA_EXEC, -1, -1, path_guess, 0); } - pseudo_setupenv(); - if (pseudo_has_unload(NULL)) - pseudo_dropenv(); + /* Due to bash intercepting setenv/getenv/unsetenv and changing environ + internally itself at will, we create our own environ copy at process + creation based on it to ensure it is correct */ + orig_environ = environ; + new_environ = pseudo_setupenvp(environ); + if (pseudo_has_unload(new_environ)) + new_environ = pseudo_dropenvp(new_environ); + environ = new_environ; /* if exec() fails, we may end up taking signals unexpectedly... * not much we can do about that. @@ -30,6 +36,9 @@ sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL); rc = real_execvp(file, argv); + environ = orig_environ; + free(new_environ); + /* return rc; * } */ diff --git a/ports/unix/guts/popen.c b/ports/unix/guts/popen.c index d19ec7e..1d48d04 100644 --- a/ports/unix/guts/popen.c +++ b/ports/unix/guts/popen.c @@ -7,15 +7,25 @@ * FILE *popen(const char *command, const char *mode) * FILE *rc = NULL; */ + char **new_environ, **orig_environ; + /* on at least some systems, popen() calls fork and exec * in ways that avoid our usual enforcement of the environment. */ - pseudo_setupenv(); - if (pseudo_has_unload(NULL)) - pseudo_dropenv(); + /* Due to bash intercepting setenv/getenv/unsetenv and changing environ + internally itself at will, we create our own environ copy at process + creation based on it to ensure it is correct */ + orig_environ = environ; + new_environ = pseudo_setupenvp(environ); + if (pseudo_has_unload(new_environ)) + new_environ = pseudo_dropenvp(new_environ); + environ = new_environ; rc = real_popen(command, mode); + environ = orig_environ; + free(new_environ); + /* return rc; * } */ diff --git a/ports/unix/guts/system.c b/ports/unix/guts/system.c index 1214314..4b374ec 100644 --- a/ports/unix/guts/system.c +++ b/ports/unix/guts/system.c @@ -7,15 +7,25 @@ * int system(const char *command) * int rc = -1; */ + char **new_environ, **orig_environ; + if (!command) return 1; - pseudo_setupenv(); - if (pseudo_has_unload(NULL)) - pseudo_dropenv(); + /* Due to bash intercepting setenv/getenv/unsetenv and changing environ + internally itself at will, we create our own environ copy at process + creation based on it to ensure it is correct */ + orig_environ = environ; + new_environ = pseudo_setupenvp(environ); + if (pseudo_has_unload(new_environ)) + new_environ = pseudo_dropenvp(new_environ); + environ = new_environ; rc = real_system(command); + environ = orig_environ; + free(new_environ); + /* return rc; * } */ diff --git a/pseudo_client.h b/pseudo_client.h index a013f88..43bbc0a 100644 --- a/pseudo_client.h +++ b/pseudo_client.h @@ -52,9 +52,6 @@ extern FILE *pseudo_grp; /* pseudo_wrappers will try to initialize these */ extern int (*pseudo_real_lstat)(const char *path, PSEUDO_STATBUF *buf); -extern int (*pseudo_real_unsetenv)(const char *); -extern char * (*pseudo_real_getenv)(const char *); -extern int (*pseudo_real_setenv)(const char *, const char *, int); extern int (*pseudo_real_fork)(void); extern int (*pseudo_real_execv)(const char *, char * const *); diff --git a/pseudo_util.c b/pseudo_util.c index 599cf31..83f92b3 100644 --- a/pseudo_util.c +++ b/pseudo_util.c @@ -72,15 +72,9 @@ typedef struct { char *data; } pseudo_evlog_entry; -/* so bash overrides getenv/unsetenv/etcetera, preventing them from - * actually modifying environ, so we have pseudo_wrappers try to dlsym - * the right values. This could fail, in which case we'd get null - * pointers, and we'll just call whatever the linker gives us and - * hope for the best. - */ -#define SETENV(x, y, z) (pseudo_real_setenv ? pseudo_real_setenv : setenv)(x, y, z) -#define GETENV(x) (pseudo_real_getenv ? pseudo_real_getenv : getenv)(x) -#define UNSETENV(x) (pseudo_real_unsetenv ? pseudo_real_unsetenv : unsetenv)(x) +#define SETENV(x, y, z) setenv(x, y, z) +#define GETENV(x) getenv(x) +#define UNSETENV(x) unsetenv(x) #define PSEUDO_EVLOG_ENTRIES 250 #define PSEUDO_EVLOG_LENGTH 256 diff --git a/pseudo_wrappers.c b/pseudo_wrappers.c index 9ae1200..112239b 100644 --- a/pseudo_wrappers.c +++ b/pseudo_wrappers.c @@ -173,12 +173,6 @@ pseudo_init_wrappers(void) { pseudo_real_fsetxattr = real_fsetxattr; #endif pseudo_real_lstat = base_lstat; - /* bash has its own local copies of these which it uses - * instead of ours... - */ - pseudo_real_unsetenv = dlsym(RTLD_NEXT, "unsetenv"); - pseudo_real_getenv = dlsym(RTLD_NEXT, "getenv"); - pseudo_real_setenv = dlsym(RTLD_NEXT, "setenv"); /* and these are used so the client's server spawn can bypass * wrappers. */ From patchwork Wed Jul 1 13:13:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Purdie X-Patchwork-Id: 91510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0AEAC44501 for ; Wed, 1 Jul 2026 13:13:52 +0000 (UTC) Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.44678.1782911628739097363 for ; Wed, 01 Jul 2026 06:13:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=NKitCg/U; spf=pass (domain: linuxfoundation.org, ip: 209.85.221.43, mailfrom: richard.purdie@linuxfoundation.org) Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-4759b4f0897so497121f8f.1 for ; Wed, 01 Jul 2026 06:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1782911627; x=1783516427; darn=lists.yoctoproject.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=w1+SRdj20u5uV7luAfrwrs55sSE1VKgdD+9XdW4V9II=; b=NKitCg/UKyzoKqOojiBZFwF23U+QtOvwaSGw7WDPA2jZz/Dv39ukp6al4lmbZTuz2/ VKljFH8MnvtSTf3BqcfemWrWLbsCz7P1pXkYiz1eFZEYuc2aLq/qiROSsIihl+wKeNKW OWWjzLjQb9+V5xGqnxLaZNEng/6u6QoTSw2H0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782911627; x=1783516427; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=w1+SRdj20u5uV7luAfrwrs55sSE1VKgdD+9XdW4V9II=; b=cRK8ALE0sWav+bATm+HByx8Bhhr1sOQ1ajfs4JTlDIRTcJj2AhNwoMzgYXwcCXaXPp Kd0CpkEJj36PrQoD9m9aIIcwmyeDCwbvT8HsOeSRuIF2+7GysXDRfO2PVCYIplWGiPUU XeO8IjyflCJ+FctyiOtOaQJM16FMgCp/wzVdZB8f5j2Q7oeaKbMWYiZ/528GC3N4dCd+ Br7bDKTQSsoQCusxE5NIgznS/5QsGNYrdIUjAZ5rLIMe+puJMHC87pDrtQxFScTUaJM8 RcdULrEJNRnNXl8KrEGwP0o0QVOtLFc2AQdmLdLQBohFT8p9YAjcAtYkx36476ocBQ/N 3Zqw== X-Gm-Message-State: AOJu0YwSLTSusQL9bHx8810icgesUs9j4V4D22KoHjsvGYE+oIRuCJSu UeBzSuERTD8BYTX3p0wbxGelVXEP2pN0ODlpk2UMAjqmoOwm9H7cXPkBJN9i2syENcdlRfaMinW 37Vyj X-Gm-Gg: AfdE7cnqhziUXpGWVgk5dhQk/A67xizhV9gxYChSZdYhgBZLoRINH4i39ai9gMvuaky m5nwaXU/tM8Mp5FXp1e9LJkomkuD5G71d9+h78rNyuFqMML/uF99zNG9c+7xbfupvUJ+KNjH8yd vxxoYkxRkTUEvASETLiNuMR3rWSHm2JZJ54sTsSv61Hu4PMbDqv+QGlfIJ/P1yuULZe+nsP1cLS YowQtEa9yq4cT3BS/7scE3yaZq1/X3i4DfYtvrVUNSU9PnIHC77bEEOaIphsj8RCUo2wVBRK2Ol KS7D0jN82kSzDfhKDfp6qcjDGVa2Vq6eigTrF6SnzJEkdKfjmO56fCyukyyt+sk7hQy1sKqgaf5 Z/aFFQHjt/bqWxqF+ygSk+3vEH5Cdby7cq3RpjzUryiZ2ls3AbdWkJCrqHsNpN8i3shG53ZP13z tEXNWWTYUy7b/e0X8zNJGFG8jlq+1oluZpAWlg20rfHg== X-Received: by 2002:a05:6000:46c6:b0:461:a15f:6df4 with SMTP id ffacd0b85a97d-477b4fb2b7dmr451014f8f.35.1782911627010; Wed, 01 Jul 2026 06:13:47 -0700 (PDT) Received: from max.int.rpsys.net ([2001:8b0:aba:5f3c:6b3f:20f2:ee05:f032]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47567884770sm17568280f8f.33.2026.07.01.06.13.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 06:13:44 -0700 (PDT) From: Richard Purdie To: yocto-patches@lists.yoctoproject.org Cc: seebs@seebs.net, mark.hatle@kernel.crashing.org Subject: [pseudo] [PATCH 7/7] pseudo_util: Correctly free memory allocated by pseudo_setupenvp Date: Wed, 1 Jul 2026 14:13:36 +0100 Message-ID: <20260701131336.3578279-7-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> References: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 01 Jul 2026 13:13:52 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/4349 Add a function to properly clean up the environment array memory after use. Signed-off-by: Richard Purdie --- ports/common/guts/execv.c | 2 +- ports/common/guts/execve.c | 2 +- ports/common/guts/execvp.c | 2 +- ports/common/guts/posix_spawn.c | 2 +- ports/common/guts/posix_spawnp.c | 2 +- ports/unix/guts/popen.c | 2 +- ports/unix/guts/system.c | 2 +- pseudo.h | 1 + pseudo_util.c | 11 +++++++++++ 9 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ports/common/guts/execv.c b/ports/common/guts/execv.c index eb328ed..d4031b3 100644 --- a/ports/common/guts/execv.c +++ b/ports/common/guts/execv.c @@ -37,7 +37,7 @@ rc = real_execv(file, argv); environ = orig_environ; - free(new_environ); + pseudo_free_envp(new_environ); /* return rc; * } diff --git a/ports/common/guts/execve.c b/ports/common/guts/execve.c index c2be66e..de2f1d4 100644 --- a/ports/common/guts/execve.c +++ b/ports/common/guts/execve.c @@ -30,7 +30,7 @@ sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL); rc = real_execve(file, argv, new_environ); - free(new_environ); + pseudo_free_envp(new_environ); /* return rc; * } diff --git a/ports/common/guts/execvp.c b/ports/common/guts/execvp.c index 177e4ee..ffc94be 100644 --- a/ports/common/guts/execvp.c +++ b/ports/common/guts/execvp.c @@ -37,7 +37,7 @@ rc = real_execvp(file, argv); environ = orig_environ; - free(new_environ); + pseudo_free_envp(new_environ); /* return rc; * } diff --git a/ports/common/guts/posix_spawn.c b/ports/common/guts/posix_spawn.c index 5896893..46ebb0e 100644 --- a/ports/common/guts/posix_spawn.c +++ b/ports/common/guts/posix_spawn.c @@ -29,7 +29,7 @@ sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL); rc = real_posix_spawn(pid, path, file_actions, attrp, argv, new_environ); - free(new_environ); + pseudo_free_envp(new_environ); /* return rc; * } diff --git a/ports/common/guts/posix_spawnp.c b/ports/common/guts/posix_spawnp.c index f3dc16b..194bcb3 100644 --- a/ports/common/guts/posix_spawnp.c +++ b/ports/common/guts/posix_spawnp.c @@ -29,7 +29,7 @@ sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL); rc = real_posix_spawnp(pid, file, file_actions, attrp, argv, new_environ); - free(new_environ); + pseudo_free_envp(new_environ); /* return rc; * } diff --git a/ports/unix/guts/popen.c b/ports/unix/guts/popen.c index 1d48d04..1ce083d 100644 --- a/ports/unix/guts/popen.c +++ b/ports/unix/guts/popen.c @@ -24,7 +24,7 @@ rc = real_popen(command, mode); environ = orig_environ; - free(new_environ); + pseudo_free_envp(new_environ); /* return rc; * } diff --git a/ports/unix/guts/system.c b/ports/unix/guts/system.c index 4b374ec..12a3aff 100644 --- a/ports/unix/guts/system.c +++ b/ports/unix/guts/system.c @@ -24,7 +24,7 @@ rc = real_system(command); environ = orig_environ; - free(new_environ); + pseudo_free_envp(new_environ); /* return rc; * } diff --git a/pseudo.h b/pseudo.h index a2d402c..93a1cea 100644 --- a/pseudo.h +++ b/pseudo.h @@ -69,6 +69,7 @@ extern void pseudo_dropenv(void); extern char **pseudo_dropenvp(char **); extern void pseudo_setupenv(void); extern char **pseudo_setupenvp(char * const *); +extern void pseudo_free_envp(char **envp); extern char *pseudo_prefix_path(char *); extern char *pseudo_bindir_path(char *); extern char *pseudo_libdir_path(char *); diff --git a/pseudo_util.c b/pseudo_util.c index 83f92b3..729b65d 100644 --- a/pseudo_util.c +++ b/pseudo_util.c @@ -1250,6 +1250,17 @@ pseudo_setupenvp(char * const *envp) { return new_envp; } +/* Free data allocated by pseudo_setupenvp() */ +void +pseudo_free_envp(char **envp) { + int i; + + for (i = 0; envp && envp[i]; ++i) { + free(envp[i]); + } + free(envp); +} + /* Append the file value to the prefix value. */ char * pseudo_append_path(const char * prefix, size_t prefix_len, char *file) {