From patchwork Wed Jul 24 21:05:13 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: 1964491 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=XnIlk5+r; 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 4WTmlf3w1Cz1yY9 for ; Thu, 25 Jul 2024 07:06:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C44723858283 for ; Wed, 24 Jul 2024 21:06:20 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id C26303858C66 for ; Wed, 24 Jul 2024 21:05:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C26303858C66 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 C26303858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::330 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721855122; cv=none; b=nDlPAO2wI3Xq9D5xi4+RxYfUFrwYeDMzfUyzns9ARRJb7D3M/Lk65kk/tCxDgf1RgH6MtMsLdtGMaM6pBRZeWbtCG8/XfQ1EKxLcpnuY/T9gg6MNOqXw5G8L2SkdLZWGeXuchksLoktX8p0EEFyMc00J6swge6FwugJPcO/ilg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721855122; c=relaxed/simple; bh=FGsZyrC++GHHxKHnA/EZcn4P7e8859PQJyzH+zw55tw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=cVOQyVpDhXrpKemvRLhPv7W0hJVyQYVhwSCdKG+VBicSqWJz3st1hvNnbFcW4JcReisOh7NyZuMCIOMpdyuyV4ZZM5aw8YGgBhieww+ajlTbxTsJpauri/MqjBIzT/1AbwwUIMH5ZFe02Jwytn4MRwq+1DlzW1Qy0p7DbBFTKqU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-7091558067eso63670a34.3 for ; Wed, 24 Jul 2024 14:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721855120; x=1722459920; 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=XnIlk5+rIeS8OwUnZoP3kYIfreBz9HMstrd898xFuAqt0B4p3GoIKpX9GJpS3hHjAa MPz2fbvkFq87RHscIwznXwbiAubZeFjf8CqX52/G+NbJJeg5wwAKZFcvRo1KxAzvDmy5 nMqrPubsmvZJ/RzZCz92yqxSx/GJHjR8P11pl9MZn7VE0aAwsJbhMb7fQooHA6rpeTWk clIxx/cAlNuRV1eSFzbyrQHu1A8NrW/aFBSl6gTXiT9emTI0Wtlq5aMDuGdb9zxFWpi0 J+5xdj1MuUe8QVTs9DNyh89hm5N/WcwMuTLJMnO9EXH6QN7mZv1r+A80L88lsmu9lmRi 9MIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721855120; x=1722459920; 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=rMdFTDXMGZIVehfpc4loosBGlED/r6uvp3PjFNYLhgeRP/TUmPYUB6bV1sJWDQ8Uvg U2Hgoy0hLDGKmeYLLvENJ9xetOz8KX/ONoQqRopUeb/xhLYcy7DFZDGyebBLtJdLjiBX /KR4sP465izehhLmjrQu4LhPFcqCqTYIg2OVK60mITm2MkZMa9spSWR+bsAqS5MZ3FcW yAwPq9uwMQfctAwev/MrkFRiHbiSPYM5umw0jf/W7dIRGlC4iEelZv2MCyArTyz8BqyV UFC8+rXT52xusO8l86mmCpr8mzEcUO33BrAi3vgTo1dDja1l9KiQ+z329N7nVklzoHxb h36A== X-Gm-Message-State: AOJu0Yx/BPXEERotu0ZhsdqoGj8DAObPg1Ex88raMlU6mdozPSwXYb/8 S9rbCW5x6Y/cUhrm3YVmjCunWMnYBxuLPjanQfLFFWHmNPPCpp/So8TpKoU/cNvPIA== X-Google-Smtp-Source: AGHT+IEctgCHzWMhMi8sMVv7pvuCpxCQcnqMR3J6KxjPlIldQdGSSCMOW4uGY5NareK4F97RCNkY2Q== X-Received: by 2002:a05:6830:3883:b0:703:5b40:1925 with SMTP id 46e09a7af769-7092e76183bmr1243302a34.28.1721855119826; Wed, 24 Jul 2024 14:05:19 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.160.33]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a1d7435ccfsm2092785a.91.2024.07.24.14.05.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 14:05:19 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 2DB87C024B for ; Wed, 24 Jul 2024 14:05:15 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH v4 1/3] linux: Update the mremap C implementation [BZ #31968] Date: Wed, 24 Jul 2024 14:05:13 -0700 Message-ID: <20240724210515.473004-2-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240724210515.473004-1-hjl.tools@gmail.com> References: <20240724210515.473004-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3020.8 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 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 *);