From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/5157 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: Post-1.1.1 plans Date: Sat, 24 May 2014 10:13:20 +0200 Message-ID: <20140524081320.GH12324@port70.net> References: <20140520223324.GA19737@brightrain.aerifal.cx> <20140522044445.GH507@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="9UV9rz0O2dU/yYYn" X-Trace: ger.gmane.org 1400919224 20771 80.91.229.3 (24 May 2014 08:13:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 24 May 2014 08:13:44 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-5162-gllmg-musl=m.gmane.org@lists.openwall.com Sat May 24 10:13:38 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Wo75E-0002H9-4t for gllmg-musl@plane.gmane.org; Sat, 24 May 2014 10:13:36 +0200 Original-Received: (qmail 25916 invoked by uid 550); 24 May 2014 08:13:33 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 25904 invoked from network); 24 May 2014 08:13:33 -0000 Content-Disposition: inline In-Reply-To: <20140522044445.GH507@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:5157 Archived-At: --9UV9rz0O2dU/yYYn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline * Rich Felker [2014-05-22 00:44:45 -0400]: > On Tue, May 20, 2014 at 06:33:25PM -0400, Rich Felker wrote: > > A few things I want to work on either adding or making decisions > > about, aside from the existing roadmap items: > > > > - Stuff left in the "Open issues at end of April" thread: > > - Renaming _start in dynamic linker (annoying for debugging) > > - Resolving max_align_t issue and adding it > > - Pending __xmknod and __sysv_signal patch (ABI compat) > > - Pending fmtmsg patch (probably ok as-is) > > - Adding recvmmsg/sendmmsg (waiting on Timo, I think) > > - The if_nameindex/getifaddrs issue > > - LINE_MAX vs sysconf(_SC_LINE_MAX) issue > > - Proposed errc/etc. addition to err.h > > - And error.h? > > - Whether to add default timezone from /etc? > > - reallocarray and explicit_bzero request > > One more I omitted: I have a pending patch for siginfo_t that fixes up > some technical issues with the hideous union hackery. i attach a mips RLIM_INFINITY patch so does not get forgotten --9UV9rz0O2dU/yYYn Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-workaround-for-broken-kernel-side-RLIM_INFINITY-hand.patch" >From b5d429f7cd357a8cf8e49480d58b083892e209f0 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 24 May 2014 00:14:27 +0200 Subject: [PATCH] workaround for broken kernel side RLIM_INFINITY handling on mips On 32 bit mips the kernel uses -1UL/2 to mark RLIM_INFINITY (and this is the definition in the userspace api), but since it is in the middle of the valid range of limits and limits are often compared with relational operators, various kernel side logic is broken if larger than -1UL/2 limits are used. So we truncate the limits to -1UL/2 in get/setrlimit and prlimit. Even if the kernel side logic consistently treated -1UL/2 as greater than any other limit value, there wouldn't be any clean workaround that allowed using large limits: * using -1UL/2 as RLIM_INFINITY in userspace would mean different infinity value for get/setrlimt and prlimit (where infinity is always -1ULL) and userspace logic could break easily (just like the kernel is broken now) and more special case code would be needed for mips. * translating -1UL/2 kernel side value to -1ULL in userspace would mean that -1UL/2 limit cannot be set (eg. -1UL/2+1 had to be passed to the kernel instead). --- arch/mips/bits/resource.h | 2 ++ src/linux/prlimit.c | 20 ++++++++++++++++++++ src/misc/getrlimit.c | 10 ++++++++++ src/misc/setrlimit.c | 6 ++++++ 4 files changed, 38 insertions(+) diff --git a/arch/mips/bits/resource.h b/arch/mips/bits/resource.h index 414a405..4d8e43b 100644 --- a/arch/mips/bits/resource.h +++ b/arch/mips/bits/resource.h @@ -1,3 +1,5 @@ +#define __broken_RLIM_INFINITY + #define RLIMIT_NOFILE 5 #define RLIMIT_AS 6 #define RLIMIT_RSS 7 diff --git a/src/linux/prlimit.c b/src/linux/prlimit.c index d1639cc..12a9ba9 100644 --- a/src/linux/prlimit.c +++ b/src/linux/prlimit.c @@ -3,10 +3,30 @@ #include "syscall.h" #include "libc.h" +#ifdef __broken_RLIM_INFINITY +#define FIX(x) ((x) >= -1UL/2 ? RLIM_INFINITY : (x)) +int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit) +{ + struct rlimit tmp; + int r; + if (new_limit) { + tmp.rlim_cur = FIX(new_limit->rlim_cur); + tmp.rlim_max = FIX(new_limit->rlim_max); + new_limit = &tmp; + } + r = syscall(SYS_prlimit64, pid, resource, new_limit, old_limit); + if (old_limit) { + old_limit->rlim_cur = FIX(old_limit->rlim_cur); + old_limit->rlim_max = FIX(old_limit->rlim_max); + } + return r; +} +#else int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit) { return syscall(SYS_prlimit64, pid, resource, new_limit, old_limit); } +#endif #undef prlimit64 LFS64(prlimit); diff --git a/src/misc/getrlimit.c b/src/misc/getrlimit.c index b7bbd06..a6097cf 100644 --- a/src/misc/getrlimit.c +++ b/src/misc/getrlimit.c @@ -3,14 +3,24 @@ #include "syscall.h" #include "libc.h" +#ifdef __broken_RLIM_INFINITY +#define FIX(x) ((x) >= -1UL/2 ? RLIM_INFINITY : (x)) +#else +#define FIX(x) (x) +#endif + int getrlimit(int resource, struct rlimit *rlim) { unsigned long k_rlim[2]; int ret = syscall(SYS_prlimit64, 0, resource, 0, rlim); + rlim->rlim_cur = FIX(rlim->rlim_cur); + rlim->rlim_max = FIX(rlim->rlim_max); if (!ret || errno != ENOSYS) return ret; if (syscall(SYS_getrlimit, resource, k_rlim) < 0) return -1; + k_rlim[0] = FIX(k_rlim[0]); + k_rlim[1] = FIX(k_rlim[1]); rlim->rlim_cur = k_rlim[0] == -1UL ? RLIM_INFINITY : k_rlim[0]; rlim->rlim_max = k_rlim[1] == -1UL ? RLIM_INFINITY : k_rlim[1]; return 0; diff --git a/src/misc/setrlimit.c b/src/misc/setrlimit.c index ddc13e9..665b67d 100644 --- a/src/misc/setrlimit.c +++ b/src/misc/setrlimit.c @@ -8,6 +8,12 @@ int __setrlimit(int resource, const struct rlimit *rlim) { unsigned long k_rlim[2]; +#ifdef __broken_RLIM_INFINITY + struct rlimit tmp; + tmp.rlim_cur = MIN(rlim->rlim_cur, -1UL/2); + tmp.rlim_max = MIN(rlim->rlim_max, -1UL/2); + rlim = &tmp; +#endif int ret = __syscall(SYS_prlimit64, 0, resource, rlim, 0); if (ret != -ENOSYS) return ret; k_rlim[0] = MIN(rlim->rlim_cur, -1UL); -- 1.7.10.4 --9UV9rz0O2dU/yYYn--