From patchwork Wed Sep 9 05:19:53 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinal Kumar X-Patchwork-Id: 143193 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A4394BB1C3B for ; Wed, 9 Sep 2026 05:20:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A4394BB1C3B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=YTje8fOo X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 0DF704BB1C2B for ; Wed, 9 Sep 2026 05:20:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0DF704BB1C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0DF704BB1C2B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788931208; cv=none; b=MF/OVzcdkQdoPBs9CXW6iGCJmE4EUOJopCA6Qoquk3b0//7cRqE39vzmhVamVp5//XZFOvmgGcAnP840x8FXge0/bc5362NDarwo4q6iMpyTJIfvA/JEE+gRyEO3gtC/qAbzILzhfF8RTxVRpJneS/GyxeLyz8PPK2s4BIf6dMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788931208; c=relaxed/simple; bh=mjwYJ/DQakS+8hVmPsmdaT3TJNDCSFQ/o+ms+L1POFI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eJRG+U8q+I7JF0912oJjP6AWp9x92aU8JT25/En98rOCSV9b1IlqkxWeSxI+TabFLF+XyYvtYx6pDFLXtg7Bre9Sv2YrcxayIhhAZvNFUrFixqY9z2aMxIflBXjCuIQvivAlaUqwdRdwfJZToGUuhnibALc67A7LRCiz3sAXzyw= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=YTje8fOo DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DF704BB1C2B Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-852c481415fso6656418b3a.3 for ; Tue, 08 Sep 2026 22:20:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788931207; x=1789536007; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=nvhp+Qab7EqmVhCUT2wrPl3HoMWwLoe+Q2DLOCxH7b8=; b=YTje8fOo4yfLB/2jrGSH7MVHZtGSCa7BCy1lWw6HzixZbzuP5FgKsyr/EuKzMG0QQZ SMAvH2pV/NP8ZmU0anyNT1xFg8o0zAhZcO17dJ0a+NQ9J/xZei8T4Gc4/bdmVT9JrSpF TyIPHYgiWzESP9NvIu2NhL0N6lFoYJakgAm12qewmaNFs1cUgvUxPlo306butVFB6ip5 iIrohEL4z8M2PyANQ4SbeW3OTRh81/C+XaxdUbbU2+D9z4/DN5ULNpaqSBR5RIJ+17Pn 5n0k0ihrOodZ+n3AEXBf/Bk8BskxtWZfCpbUQ9XJHBQ4VtZVOGE/puUU/vrleraq0ut2 L7ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788931207; x=1789536007; 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:content-type; bh=nvhp+Qab7EqmVhCUT2wrPl3HoMWwLoe+Q2DLOCxH7b8=; b=kHZbZFyJEfiPEcZX1R4clO45IfBM4CmIUvSJ4qovdmeIY6orFjqEUNO4qQHr2NUi8E eRm9qgEy/Hkktmsay+8bRxaFmWYJl9YWv7dY2pv0WLQlPcGuom5224wb6IQIaRN2cUqd tFiFmnoPl0NFLyiNm+cJs3gC/ZMRt4xYn8bBmK/TwKN1msvGbLnDDz5xRpqXLtcZfVHB latEX0u0HL6cE67W9tPnMzvJWmG0aBR9Z0oehsb0NUhaeDO4t8lk98aIJMkkt712d3s6 YXu8EIsVcDM4sX2EkCFDtf6IWOj8Dka4ExEl4dObO1Gr5Rn1sgqHqmsCVlqIZIJBeAzP r/kA== X-Gm-Message-State: AFuF++kOFrPu5lCZs0NhHnXBE6dPDbEKX/ON9C5Gk6jsqKmTCu7mT7DD QZsvo0NdCxA+qjECHLJVh1M7fG6SuFsH/4Ap+FBYAkOUhL4KfEGJsd/c01ooPg== X-Gm-Gg: AYBFou2O5njv5kVfwNHeVk2yeKlukESRQOm1NuBTqlukDpo6MCIG/Ifu2GuYADuVGf6 RQcD3fgne63veabgDjluK1UbFplpyAhFWY0wbg5aT/g20dC9lAwZnme2U4wSd8u6e9plGi4kU6g ijl8IP8zEwqsvvtIXR0z521bXUMSWHUgXl5d/m5jDb1JN5SBaOuGtEAGLFhYGEnVT0P9mv+CYud ST1rtI4KSCstQw2SPgwK2KHOt8xE7E9S3fDUjTnqBVEbwOntzdAkY9eX0P3wVON+jti32RC/1Sw JmboDXZtM1i6C5eoOqN28E7cv7wnPw3qrpPnrXCCfZWQt0g5Xbr5L75Vqvh0Fa+ahA8qFLufnA6 Z60SY/55crGPJkmS5zDqaMlVttM1rA4zCzadNw6H4oTxhlGYLoajVRQornJf7ykGtBgI/rdu5/a qD+l80cM7HMlkKr1nytXy4qaU2WRddD4joXuUupczg9B7fLXftLV42QL3Y9YS8rszj+bEAvxC+E HOd7FtazlKWEJ8VQs6I5D5QI9fMJA6L X-Received: by 2002:a05:6a21:9f17:b0:3d3:ae0f:526d with SMTP id adf61e73a8af0-3da3a1f0463mr47765444637.25.1788931206573; Tue, 08 Sep 2026 22:20:06 -0700 (PDT) Received: from fedoraemon.neon-universe.ts.net ([2406:7400:11d:1fd2:eec2:ab88:e4ff:cced]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3339bdf26c5sm42366701eec.27.2026.09.08.22.20.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2026 22:20:06 -0700 (PDT) From: Avinal Kumar To: libc-alpha@sourceware.org Cc: bug-gettext@gnu.org, Adhemerval Zanella Subject: [PATCH v6] intl: Restrict path traversal when using LANGUAGE env var [BZ #17142, CVE-2026-84243] Date: Wed, 9 Sep 2026 10:49:53 +0530 Message-ID: <20260909051953.212230-1-avinal.xlvii@gmail.com> X-Mailer: git-send-email 2.55.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The fix for CVE-2014-0475 (Bug 17137) added valid_locale_name() in locale/findlocale.c to reject locale names containing ".." path components. However, the LANGUAGE environment variable processing in intl/dcigettext.c was not covered by that fix. An attacker who can set LANGUAGE (e.g. via SSH AcceptEnv) can force any gettext-using program to load a crafted .mo file from an arbitrary filesystem location via directory traversal. Remove the ENABLE_SECURE gate from the IS_PATH_WITH_DIR check so it applies to all binaries, not just SUID/SGID ones, and extend it to also reject the bare ".." entry which contains no directory separator but still names the parent directory. Add tst-gettext-path-traversal to verify that locale names containing path separators or equal to ".." are rejected by the LANGUAGE processing loop. This fixes bug 17142 and CVE-2026-84243. Suggested-by: Adhemerval Zanella Signed-off-by: Avinal Kumar --- Changes from v5: - Removed the bare '.' rejection, LANGUAGE=. entry simply resolves to the bound directory itself and poses no traversal risk, so filtering it is unnecessary. - Reworded NEWS entry. Even I was not sure about the ".", thank you for clarifying. NEWS | 4 +- intl/Makefile | 4 ++ intl/dcigettext.c | 8 +-- intl/tst-gettext-path-traversal.c | 83 +++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 intl/tst-gettext-path-traversal.c diff --git a/NEWS b/NEWS index 56c6b581df..8350ef1679 100644 --- a/NEWS +++ b/NEWS @@ -13,7 +13,9 @@ Major new features: Deprecated and removed features, and other changes affecting compatibility: - [Add deprecations, removals and changes affecting compatibility here] +* The gettext functions now reject LANGUAGE values containing '/' or + equal to '..' for all programs. Previously this check only applied + to SUID/SGID binaries. Changes to build and runtime requirements: diff --git a/intl/Makefile b/intl/Makefile index a8b41a1993..2547de2744 100644 --- a/intl/Makefile +++ b/intl/Makefile @@ -61,6 +61,7 @@ $(objpfx)plural.o: $(objpfx)plural.c ifeq ($(run-built-tests),yes) ifeq (yes,$(build-shared)) ifneq ($(strip $(MSGFMT)),:) +tests += tst-gettext-path-traversal tests-special += \ $(objpfx)tst-translit.out \ $(objpfx)tst-gettext.out \ @@ -125,6 +126,7 @@ $(objpfx)tst-plural-eval.out: tst-plural-eval.sh $(objpfx)tst-plural-eval $(objpfx)tst-codeset.out: $(codeset_mo) $(objpfx)tst-gettext3.out: $(codeset_mo) $(objpfx)tst-gettext5.out: $(codeset_mo) +$(objpfx)tst-gettext-path-traversal.out: $(codeset_mo) endif LOCALES := de_DE.ISO-8859-1 de_DE.UTF-8 en_US.ANSI_X3.4-1968 fr_FR.ISO-8859-1 \ @@ -139,6 +141,7 @@ $(objpfx)tst-gettext4.out: $(gen-locales) $(objpfx)tst-gettext5.out: $(gen-locales) $(objpfx)tst-gettext6.out: $(gen-locales) $(objpfx)tst-gettext-c-utf8.out: $(gen-locales) +$(objpfx)tst-gettext-path-traversal.out: $(gen-locales) $(objpfx)tst-translit.out: $(gen-locales) endif @@ -159,6 +162,7 @@ CFLAGS-tst-gettext4.c += -DOBJPFX=\"$(objpfx)\" CFLAGS-tst-gettext5.c += -DOBJPFX=\"$(objpfx)\" CFLAGS-tst-gettext6.c += -DOBJPFX=\"$(objpfx)\" CFLAGS-tst-plural-eval.c += -DOBJPFX=\"$(objpfx)\" +CFLAGS-tst-gettext-path-traversal.c += -DOBJPFX=\"$(objpfx)\" ifeq ($(have-thread-library),yes) ifeq (yes,$(build-shared)) diff --git a/intl/dcigettext.c b/intl/dcigettext.c index 43b99c2dea..e9611dae7a 100644 --- a/intl/dcigettext.c +++ b/intl/dcigettext.c @@ -591,10 +591,10 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, *cp++ = *categoryvalue++; *cp = '\0'; - /* When this is a SUID binary we must not allow accessing files - outside the dedicated directories. */ - if (ENABLE_SECURE && IS_PATH_WITH_DIR (single_locale)) - /* Ignore this entry. */ + /* Do not allow accessing files outside the dedicated + directories. */ + if (IS_PATH_WITH_DIR (single_locale) + || strcmp (single_locale, "..") == 0) continue; } diff --git a/intl/tst-gettext-path-traversal.c b/intl/tst-gettext-path-traversal.c new file mode 100644 index 0000000000..95ad326f64 --- /dev/null +++ b/intl/tst-gettext-path-traversal.c @@ -0,0 +1,83 @@ +/* Test that LANGUAGE values with path traversal are rejected [BZ #17142]. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include + +static const char *const domaindir = OBJPFX "domaindir"; +static const char *const localedir = OBJPFX "domaindir/de_DE"; +static const char *const msgdir = OBJPFX "domaindir/de_DE/LC_MESSAGES"; + +static int +do_test (void) +{ + unsetenv ("OUTPUT_CHARSET"); + /* LANGUAGE is only consulted if the locale is not "C" or "C.". + The catalog is in ISO-8859-1, as is the locale, so no conversion of + the translation takes place. */ + xsetlocale (LC_ALL, "de_DE.ISO-8859-1"); + textdomain ("codeset"); + + /* Verify that a legitimate LANGUAGE value produces the expected + translation. This exercises the normal lookup path and confirms + that the test .mo catalog is in place. */ + bindtextdomain ("codeset", domaindir); + setenv ("LANGUAGE", "de_DE", 1); + TEST_COMPARE_STRING (gettext ("cheese"), "K\344se"); + + /* A bare ".." must be rejected. Without the fix this would resolve + to msgdir/../LC_MESSAGES/codeset.mo, which is the real catalog, + so the translation would succeed. */ + bindtextdomain ("codeset", msgdir); + setenv ("LANGUAGE", "..", 1); + TEST_COMPARE_STRING (gettext ("cheese"), "cheese"); + + /* A relative path that leaves and re-enters the catalog directory + must be rejected. Without the fix this would resolve to + localedir/../de_DE/LC_MESSAGES/codeset.mo. */ + bindtextdomain ("codeset", localedir); + setenv ("LANGUAGE", "../de_DE", 1); + TEST_COMPARE_STRING (gettext ("cheese"), "cheese"); + + /* Multiple levels of directory traversal must be rejected. Without + the fix this would resolve to + msgdir/../../de_DE/LC_MESSAGES/codeset.mo. */ + bindtextdomain ("codeset", msgdir); + setenv ("LANGUAGE", "../../de_DE", 1); + TEST_COMPARE_STRING (gettext ("cheese"), "cheese"); + + /* Invalid entries in a colon-separated LANGUAGE list must be + skipped individually; valid entries that follow are still + used. */ + bindtextdomain ("codeset", domaindir); + setenv ("LANGUAGE", "..:../de_DE:de_DE", 1); + TEST_COMPARE_STRING (gettext ("cheese"), "K\344se"); + + /* A path containing "/.." must be rejected. Use localedir so the + binding changes, which invalidates the DCIGETTEXT result cache. */ + bindtextdomain ("codeset", localedir); + setenv ("LANGUAGE", "LC_MESSAGES/..", 1); + TEST_COMPARE_STRING (gettext ("cheese"), "cheese"); + + return 0; +} + +#include