DORMANTno replies

[PATCH] dup.2: Add ENOMEM to ERRORS

From: Levi Zim via B4 Relay <devnull+rsworktech.outlook.com@kernel.org>
Date: 2024-09-27 06:52:54
Also in: b4-sent, linux-man
Subsystem: the rest · Maintainer: Linus Torvalds

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]

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help