From: Levi Zim <redacted>
dup2 could return ENOMEM under extreme condition.
For example, when sysctl fs.nr_open=2147483584, and RLIMIT_NOFILE is also
2147483584. The following program fails with ENOMEM:
int main(){
int ret = dup2(0, 2000000000);
if (ret < 0) {
perror("dup2");
return 1;
}
return 0;
}
This ENOMEM comes from an allocation error here:
https://elixir.bootlin.com/linux/v6.1/source/mm/util.c#L596
ENOMEM is already documented for open(2).
Signed-off-by: Levi Zim <redacted>
---
While experimenting with fs.nr_open sysctl and RLIMIT_NOFILE,
I noticed that dup(2) could return an undocumented errno ENOMEM.
This patch add ENOMEM to ERRORS in dup.2.
---
man/man2/dup.2 | 3 +++
1 file changed, 3 insertions(+)
diff --git a/man/man2/dup.2 b/man/man2/dup.2
index ee964a827ca062d90419c7d39f457de270d42ca3..719f0ae9e78165733cbe607bbf8a803a5d0943b4 100644
--- a/man/man2/dup.2
+++ b/man/man2/dup.2
@@ -197,6 +197,9 @@ .SH ERRORS
.B RLIMIT_NOFILE
in
.BR getrlimit (2)).
+.TP
+.B ENOMEM
+Insufficient kernel memory was available.
.SH STANDARDS
.TP
.BR dup ()
---
base-commit: 1e2d36deb2de1dbaf7084bb7dc3cb2c170cce852
change-id: 20240927-dup2-727e986e1900
Best regards,
--
Levi Zim [off-list ref]