From patchwork Wed Jul 17 07:59:02 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: 1961463 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=brNif2pq; 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 4WP7d16ShNz1ySl for ; Wed, 17 Jul 2024 17:59:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 742A93839170 for ; Wed, 17 Jul 2024 07:59:31 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by sourceware.org (Postfix) with ESMTPS id 8FE1B385F025 for ; Wed, 17 Jul 2024 07:59:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8FE1B385F025 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 8FE1B385F025 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721203152; cv=none; b=GNW2ufLkoxwQAwPfjcbZbMix1wnV0vEZejTVMqjpvs3HCmpP5CsHzZ1Q936qgN9H5XJQgqCQ8e9Q7Agc9KTUjTGdD6GKSyFmqwviQhC2+StfuJOm/Es6H6sobGEDvP+fQwNJGIKYZiG2Ry06uedPD84tFHjzvcq3ZpoNLpNgCM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721203152; c=relaxed/simple; bh=FGsZyrC++GHHxKHnA/EZcn4P7e8859PQJyzH+zw55tw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LxAf/WJnsQvjVJH5OWLbgDZR6vu3yuU6yVG/EjPRg3bJTYzJgEalaI1095S/drMaDAFoYTEZYZ2RE+p02hibnMyDCRT5hZVJunO8jv+uWGZjBxt/Dq9mn9nKh5SHjVTvjpdjY1Pbq3X9B3xmUmQMLyVrMo6lj9zmHP8VPCIVHDM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-65f880c56b1so39879177b3.3 for ; Wed, 17 Jul 2024 00:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721203150; x=1721807950; 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=brNif2pqOBYMV9hhgGgvqXSLf2hzRo/LSmYCuNvAiBWaolU2Pfum38ciobqyWtTcOz 6hGGRZZ7pDRt+TZltHp12k0JT1YIsSkrJ7FIIMAD6/pHzErP9ZClVUUj0drn8NYJfiqp PWYdX1GpuW4Jhft5+zY+eoqwcN+Urn1HhJ+TKpBuWxTIDeAEzC+UVu6nASgJiYwch7b3 aNbpO4u19EKTxzihRmgirwIBbjhBb6UJSyXLkKcNS30vF+4H1NFh9UMMGPk4SRrV55pA vx4cUzsV/EmdaMqrNlmRcm6eCyY8NcPIfoUBWxGPk6gwt1k79bdTD5PEsncFGUQKgTNv h+2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721203150; x=1721807950; 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=lzUE7Gmk4Qq5zgHbQKfgQvoigM2gC8/OnAneappq3SZdZHe3D+ISQDIKAgqSwmT+yA n6MhWlb0dJxmixf4UTMGoJQbhIL1Rtu/pogksjyy7EMYXwRfVYxJ/B+XT6eyRHiAlJJZ xFllhkSW+dbwO3EYFkY/wiPHRY0/AV7S6i6IryO7pWaACfTN+B8q7t4CPE/FHYQOVRLw hKmc8iDIYPyMT3jlzZdig0DmBQHCdx1kEesF9Zgke86gEMc2U5i8T2Khm0XSd/88lolC MkFPIh9px9GHQHHz44Rli3tK/Fn973vHdd6veVR8A8rWRJDcjBabC5rq2aovENSfdhno igfQ== X-Gm-Message-State: AOJu0YzpHTuVgrDB8m02WWmcjWC75XfhbBF+SQFPUvJOndfPrmilh8iJ XkQAxngqCwtxU0otzp2P8uQ8AsEraBcdx0/gGFvs9nTmuNQtTac+p8OjjMVsk0mGqg== X-Google-Smtp-Source: AGHT+IGDSABR9mPKhjbY8vol9LyNmcLLdko/nSYcLFVbKRuS6JSEA1yyM99mhEEvPSSfb4HpdC6KMw== X-Received: by 2002:a0d:da07:0:b0:64b:630f:9f85 with SMTP id 00721157ae682-664fe45113fmr10046547b3.12.1721203149787; Wed, 17 Jul 2024 00:59:09 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.30.168]) by smtp.gmail.com with ESMTPSA id 00721157ae682-65fc4451eebsm14508657b3.117.2024.07.17.00.59.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 00:59:09 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 159DCC01AA for ; Wed, 17 Jul 2024 00:59:05 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH v3 1/3] linux: Update the mremap C implementation [BZ #31968] Date: Wed, 17 Jul 2024 00:59:02 -0700 Message-ID: <20240717075904.2365688-2-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240717075904.2365688-1-hjl.tools@gmail.com> References: <20240717075904.2365688-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3019.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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 Reviewed-by: Adhemerval Zanella --- 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 *);