From patchwork Fri Jul 12 22:31:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1960036 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=GvJ7Mds6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WLRDS0W66z1xr4 for ; Sat, 13 Jul 2024 08:32:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F533385EC54 for ; Fri, 12 Jul 2024 22:32:22 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by sourceware.org (Postfix) with ESMTPS id A565D3858433 for ; Fri, 12 Jul 2024 22:31:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A565D3858433 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 A565D3858433 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720823516; cv=none; b=lGWnL8RrLEBXelLSYoHVzOny1jUQMeiYBjtJIOm0K23xqcKqNYDFnDsfcSmnpl5IRqJieRiIDWntfZs8viOEP/1gUnRzf07675JPwg//KFmPx0e2l4o9JCR8ZmJ+5l4FO9VFjnQp+jepRl8KXFW6e6grpd626PXmpEwct7t8Rzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720823516; c=relaxed/simple; bh=FGsZyrC++GHHxKHnA/EZcn4P7e8859PQJyzH+zw55tw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XmepLV1ZTJLk02L2Nla2XOzUR1MBthzcL3DDgnQMdy1wQ0hsg9NlAn/8yZiASFYVuto4lwrtFh429W1PFwIp2fS6dNT/TpPDYcnc6atgB0op1B/K/40bTpzBHBuj/wL47RkeLstWb4gFKVgQQIaOQqYSL+ugbQrydVZJXR/9Vtg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-e036105251eso2553377276.0 for ; Fri, 12 Jul 2024 15:31:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720823513; x=1721428313; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=myFexGVoy2AKAL4T5oYuZanqraOKmWr1sfloBVgJ7Z0=; b=GvJ7Mds6l4esKu/Ib2W6Ff5ir8gDYfwESyvmadU7OChQSGNsfukyR8RpxKStxT0yST pyy+9m/+4PkZGWCow5a60przvg1fWjCRev4IFgKEzro7u1DdFP4MOU9mIXUaEcgqkSLh +EynM7FxfrVh0BCGJ7afaxTkeXPZxK6CzILwjTieyH89wmaGFk0+KkZYLinwy8c20Suq V+25XWDCPN8K/HPKapYXq24+QJe8u/1OjAWC8SsvceDQF9v4zl0I/aeA4c0qRUjHX3fF XEt8XgDhXuvIznDHj8htpR2bYlhzwZpa8BNea0rSaB2dEjFdWgUQT8sslaSjumJnxXD2 Owgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720823513; x=1721428313; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=myFexGVoy2AKAL4T5oYuZanqraOKmWr1sfloBVgJ7Z0=; b=wTUp0YCJiBvw1IaebJtpoGOBCYvEjkCPQSoWNJI+dVN4nkkM5IAdead5FssCUF5fnB SG+yBRhij8xGyHeI1Ktm+6Y8oFpiupmF72svvtjGftdhDNbaWRH2LOP6fvIcgOKlJC75 cDqLsKcj1WTawodTEuhURy8J8s8wUdrbZRCDxqkiNIIBrPhqhs1oA370K/UuqJ5cGaai jX39NMMdApVQ2oJdNZsGhilipmQVD2KusqvgInA9r4kcwH2u4OQGxQV0Gf13TIaL+e2M wtpJHXPDB+QmsHT4hLo4+UQY+WJfzW/CXePyRCwdqRVxGlE8dv+K4c7o3YIOsArJIsWz bcCg== X-Gm-Message-State: AOJu0Yy8YfrworAEcpZZKG22zep4+h40ZSdNOc0EqfFwAw8kWgsG20Fh paQV3ppYcuNflt1OoJXvJO6Lr9jfC/KVwxPw9HhecDquLvNid1yWgjgHBGBJzcKbsA== X-Google-Smtp-Source: AGHT+IGQCcyLVHajCUDzwwWf/UNOu26ItmE0nyy/z/ABvLCZqaUNyfM72i1EZQ5H9QlPzO8RJJ0FOQ== X-Received: by 2002:a25:ac8d:0:b0:e02:bd5c:bfa9 with SMTP id 3f1490d57ef6-e041b059553mr14845539276.19.1720823513643; Fri, 12 Jul 2024 15:31:53 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.160.179]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e041a8f5f59sm1421547276.34.2024.07.12.15.31.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 15:31:53 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 98E92C020E for ; Fri, 12 Jul 2024 15:31:47 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH 1/3] linux: Update the mremap C implementation [BZ #31968] Date: Fri, 12 Jul 2024 15:31:45 -0700 Message-ID: <20240712223147.1809816-2-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712223147.1809816-1-hjl.tools@gmail.com> References: <20240712223147.1809816-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3021.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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~incoming=patchwork.ozlabs.org@sourceware.org Update the mremap C implementation to support the optional argument for MREMAP_DONTUNMAP added in Linux 5.7 since it may not always be correct to implement a variadic function as a non-variadic function on all Linux targets. Return MAP_FAILED and set errno to EINVAL for unknown flag bits. This fixes BZ #31968. Note: A test must be added when a new flag bit is introduced. Signed-off-by: H.J. Lu --- sysdeps/unix/sysv/linux/mremap.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sysdeps/unix/sysv/linux/mremap.c b/sysdeps/unix/sysv/linux/mremap.c index 4f770799c4..1ada5c1f40 100644 --- a/sysdeps/unix/sysv/linux/mremap.c +++ b/sysdeps/unix/sysv/linux/mremap.c @@ -20,6 +20,12 @@ #include #include #include +#include + +#define MREMAP_KNOWN_BITS \ + (MREMAP_MAYMOVE \ + | MREMAP_FIXED \ + | MREMAP_DONTUNMAP) void * __mremap (void *addr, size_t old_len, size_t new_len, int flags, ...) @@ -27,7 +33,13 @@ __mremap (void *addr, size_t old_len, size_t new_len, int flags, ...) va_list va; void *new_addr = NULL; - if (flags & MREMAP_FIXED) + if (flags & ~(MREMAP_KNOWN_BITS)) + { + __set_errno (EINVAL); + return MAP_FAILED; + } + + if (flags & (MREMAP_FIXED | MREMAP_DONTUNMAP)) { va_start (va, flags); new_addr = va_arg (va, void *);