From patchwork Tue Nov 7 11:03:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Kozlov X-Patchwork-Id: 1860974 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=pfptdkimsnps header.b=Yd1HYprS; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=mail header.b=QC/wzWUg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=uclibc-ng.org (client-ip=89.238.66.15; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=patchwork.ozlabs.org) Received: from helium.openadk.org (helium.openadk.org [89.238.66.15]) (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 4SPlhH2cLqz1yQL for ; Tue, 7 Nov 2023 22:03:43 +1100 (AEDT) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id A6CE53520ED1; Tue, 7 Nov 2023 12:03:33 +0100 (CET) Authentication-Results: helium.openadk.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=pfptdkimsnps header.b=Yd1HYprS; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=mail header.b=QC/wzWUg; dkim-atps=neutral Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by helium.openadk.org (Postfix) with ESMTPS id 35F593520E21 for ; Tue, 7 Nov 2023 12:03:29 +0100 (CET) Received: from pps.filterd (m0098571.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A78UuaJ006698 for ; Tue, 7 Nov 2023 03:03:27 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pfptdkimsnps; bh=zDwC8xXjZrWOhlrvggFw0Mbv7xI3JQqukCSry6Q0/bE=; b=Yd1HYprSLskHp9x4u/3OIx/kS+5op3+fLIElDEvKKsoLBC4DnfYf14u1i76IJodwZ1CL iU+C+pohe+pDioa4XajiBvH51yTMvrwzRDQ1w2bYzNm3/uHbVHGugCaSj4uxWnxII1xA IyxriQk56O6PneVoPTulobY8cSNL9CHIdp45t8fiVP2AgXJXmkZpiqXsMZYTwcbYDLOo l0oTcmMUu+3rrRRU03um2MfumfDL0BR9WWtadqqOMwiqrcynuMMmdMMBT9WsSdiIS8A2 7+fGOdvNX3tXu+LQORkfNdokejn6u7ZhK4VNV8S/rUZOVNU78X9QWruDmRhhfj3Vjqq5 uQ== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3u5myqu5hr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 07 Nov 2023 03:03:26 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1699355006; bh=fg2IdFa1NbYZ82rVLz/PNeQQ4+r3qS5Oi09Hpe5SUJw=; h=From:To:Cc:Subject:Date:From; b=QC/wzWUgY3SQUGJBrDhZSaceh5A+JY8RrFwOKOTxvZ/WqBgkilbg5DirptCtV3JEO +/3hkpEScEaeJYyEPNgLD1E4tgyLsTmMpGNSE0ADVyti9aXswDPT4pszFl0PvaUkoH E0axG0HEiN0n6IzAD68v3XIONfwSpAkEu6w9AROe9AEJmlrC5T6zLquySQmyg86OGU w6Qa2I4qMykaRVEsvRLWrsg55aGefE6huZgVL2A4ZyyMBSTfU48ALW2BD6QROK4Yei EBLkOML1rPzJDjgj3XLpYC/oQxHaUe2gHi/GF5+z5XVPysMELCCKqwPqvZCpM7xGZL rsCFFb6b2s38g== Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) client-signature RSA-PSS (2048 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 544684045F for ; Tue, 7 Nov 2023 11:03:26 +0000 (UTC) Received: from SNPS-o0WHuHJU73.internal.synopsys.com (snps-o0whuhju73.internal.synopsys.com [10.116.104.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id C8070A006D; Tue, 7 Nov 2023 11:03:24 +0000 (UTC) X-SNPS-Relay: synopsys.com From: Pavel Kozlov To: devel@uclibc-ng.org Date: Tue, 7 Nov 2023 15:03:12 +0400 Message-Id: <20231107110312.30800-1-kozlov@synopsys.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: J3BvhKpvUi5WqZbbGVHIb6dwBxOnmUBC X-Proofpoint-GUID: J3BvhKpvUi5WqZbbGVHIb6dwBxOnmUBC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-07_01,2023-11-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 adultscore=0 mlxlogscore=714 spamscore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 phishscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310240000 definitions=main-2311070091 Message-ID-Hash: NDND7DCUPAXLIFWXO3QLEROFLHLVDB2J X-Message-ID-Hash: NDND7DCUPAXLIFWXO3QLEROFLHLVDB2J X-MailFrom: Pavel.Kozlov@synopsys.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Alexey Brodkin , Pavel Kozlov X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] [PATCH] prlimit: add name redirection and fix incorrect parameters to syscall List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Pavel Kozlov The tst-rlimit/tst-rlimit64 tests pointed to several issueses in prlimit() function for 32-bit CPUs. This patch adds name redirection to prlimit64 in prlimit declaration to provide correct support for 64-bit offset (_FILE_OFFSET_BITS=64) on 32-bit CPUs and fixes improper field assignment and incorrect syscall paramerets in the prlimit() function. Fixes: 8c2f6218 ("setrlimit/getrlimit: fix prlimit64 syscall use for 32-bit CPUs") Signed-off-by: Pavel Kozlov --- include/sys/resource.h | 18 +++++++++++++++--- libc/sysdeps/linux/common/prlimit.c | 9 ++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/sys/resource.h b/include/sys/resource.h index e9fac2c656bf..a5c69d84e308 100644 --- a/include/sys/resource.h +++ b/include/sys/resource.h @@ -103,13 +103,25 @@ libc_hidden_proto(setpriority) #ifdef __USE_GNU /* Modify and return resource limits of a process atomically. */ +# ifndef __USE_FILE_OFFSET64 extern int prlimit (__pid_t __pid, enum __rlimit_resource __resource, - const struct rlimit *__new_limit, - struct rlimit *__old_limit) __THROW; - + const struct rlimit *__new_limit, + struct rlimit *__old_limit) __THROW; +# else +# ifdef __REDIRECT_NTH +extern int __REDIRECT_NTH (prlimit, (__pid_t __pid, + enum __rlimit_resource __resource, + const struct rlimit *__new_limit, + struct rlimit *__old_limit), prlimit64); +# else +# define prlimit prlimit64 +# endif +# endif +# ifdef __USE_LARGEFILE64 extern int prlimit64 (__pid_t __pid, enum __rlimit_resource __resource, const struct rlimit64 *__new_limit, struct rlimit64 *__old_limit) __THROW; +# endif #endif __END_DECLS diff --git a/libc/sysdeps/linux/common/prlimit.c b/libc/sysdeps/linux/common/prlimit.c index f59ade3a379c..81c0f46193ff 100644 --- a/libc/sysdeps/linux/common/prlimit.c +++ b/libc/sysdeps/linux/common/prlimit.c @@ -25,7 +25,9 @@ prlimit (__pid_t pid, enum __rlimit_resource resource, const struct rlimit *new_rlimit, struct rlimit *old_rlimit) { struct rlimit64 new_rlimit64; + struct rlimit64 *new_rlimit64_ptr = NULL; struct rlimit64 old_rlimit64; + struct rlimit64 *old_rlimit64_ptr = (old_rlimit != NULL ? &old_rlimit64 : NULL); int res; if (new_rlimit != NULL) { @@ -37,10 +39,11 @@ prlimit (__pid_t pid, enum __rlimit_resource resource, new_rlimit64.rlim_max = RLIM64_INFINITY; else new_rlimit64.rlim_max = new_rlimit->rlim_max; + new_rlimit64_ptr = &new_rlimit64; } - res = INLINE_SYSCALL (prlimit64, 4, pid, resource, &new_rlimit64, - &old_rlimit64); + res = INLINE_SYSCALL (prlimit64, 4, pid, resource, new_rlimit64_ptr, + old_rlimit64_ptr); if (res == 0 && old_rlimit != NULL) { /* If the syscall succeeds but the values do not fit into a @@ -64,7 +67,7 @@ prlimit (__pid_t pid, enum __rlimit_resource resource, __set_errno(EOVERFLOW); return -1; } - old_rlimit->rlim_cur = RLIM_INFINITY; + old_rlimit->rlim_max = RLIM_INFINITY; } }