Skip to contentSkip to conversation

devpts: reject max=0 instead of silently lifting the limit

PATCH Applied Tao Cui 3 participants 3 messages Sep 3 – Sep 4 VFS

lore
Share & tools
lore

Tao Cui

author
#0 lore raw

PATCH 1/1 devpts: reject max=0 instead of silently lifting the limit

From: Tao Cui <[email protected]>

mount_opts.max == 0 is consumed as ida_alloc_max(..., max - 1), which wraps to 0xffffffff. The IDA layer treats a negative max as INT_MAX, so "mount -t devpts -o max=0" does not disable ptys - it lifts the per-instance limit entirely and only the global kernel.pty.max still applies.

Reject the value at parse time:

  $ mount -t devpts -o max=0 pt /tmp/pt
  mount: /tmp/pt: wrong fs type, bad option, bad superblock...

No userspace relies on 0 meaning "unlimited": runc and crun never set max=, and LXC, the only runtime that does, omits the property entirely when the configured value is 0.

The value has never been validated since the option was introduced, so there is no Fixes tag.

---
 fs/devpts/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/devpts/inode.c +2 -0
index 9844dcf354ee..bd1e8eb26edb 100644
@@ -249,6 +249,8 @@ static int devpts_parse_param(struct fs_context *fc, struct fs_parameter *param)
 	case Opt_max:
 		if (result.uint_32 > NR_UNIX98_PTY_MAX)
 			return invalf(fc, "max out of range");
+		if (result.uint_32 == 0)
+			return invalf(fc, "max must be greater than 0");
 		opts->max = result.uint_32;
 		break;
 	}
Signature · 1 line
2.43.0
#1 lore raw
Quoted 13 lines · Tao Cui

From: Tao Cui <[email protected]>

mount_opts.max == 0 is consumed as ida_alloc_max(..., max - 1), which wraps to 0xffffffff. The IDA layer treats a negative max as INT_MAX, so "mount -t devpts -o max=0" does not disable ptys - it lifts the per-instance limit entirely and only the global kernel.pty.max still applies.

Reject the value at parse time:

  $ mount -t devpts -o max=0 pt /tmp/pt
  mount: /tmp/pt: wrong fs type, bad option, bad superblock...
Quoted 6 lines

No userspace relies on 0 meaning "unlimited": runc and crun never set max=, and LXC, the only runtime that does, omits the property entirely when the configured value is 0.

The value has never been validated since the option was introduced, so there is no Fixes tag.

Shouldn't the Fixes tag be where the option was introduced?

Anyway, not all that big of a deal as this is a root-only thing.

thanks,

greg k-h

maintainer Applied
#2 lore raw
In reply to Tao Cui
Quoted 1 line · Tao Cui

devpts: reject max=0 instead of silently lifting the limit

I'll figure out the Fixes tag.

---

Applied to the vfs-7.4.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.4.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.4.misc

[1/1] devpts: reject max=0 instead of silently lifting the limit

      https://git.kernel.org/vfs/vfs/c/7d1d1a34d29c