mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: Post-1.1.1 plans
Date: Sat, 24 May 2014 10:13:20 +0200	[thread overview]
Message-ID: <20140524081320.GH12324@port70.net> (raw)
In-Reply-To: <20140522044445.GH507@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 1038 bytes --]

* Rich Felker <dalias@libc.org> [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

[-- Attachment #2: 0001-workaround-for-broken-kernel-side-RLIM_INFINITY-hand.patch --]
[-- Type: text/x-diff, Size: 4101 bytes --]

From b5d429f7cd357a8cf8e49480d58b083892e209f0 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
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


      reply	other threads:[~2014-05-24  8:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-20 22:33 Rich Felker
2014-05-21  1:01 ` Laurent Bercot
2014-05-21  1:36   ` Rich Felker
2014-05-21  6:15 ` Timo Teras
2014-05-21 12:59   ` Rich Felker
2014-05-22  4:44 ` Rich Felker
2014-05-24  8:13   ` Szabolcs Nagy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140524081320.GH12324@port70.net \
    --to=nsz@port70.net \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).