[PATCH] devpts: fix pty count limit off by one

Yichong Chen <[email protected]>
Newsgroups gmane.linux.kernel,gmane.linux.serial
Message-ID <[email protected]>
devpts_new_index() increments the global pty count before checking it
against the effective global limit. The check currently rejects a new pty
when the incremented count is equal to the limit.

This makes kernel.pty.max allow only max - 1 ptys. For example, if
kernel.pty.nr is 3 and kernel.pty.max is set to 4, opening /dev/ptmx
fails with -ENOSPC even though one more pty should be allowed.

Allow the incremented count to be equal to the effective limit and reject
only counts above it.

Fixes: 0f0a0e54a2a1 ("devpts: Convert to new IDA API")
Signed-off-by: Yichong Chen <[email protected]>
---
 fs/devpts/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 9844dcf354ee..853cc4c03e73 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -467,7 +467,7 @@ int devpts_new_index(struct pts_fs_info *fsi)
 {
 	int index = -ENOSPC;
 
-	if (atomic_inc_return(&pty_count) >= (pty_limit -
+	if (atomic_inc_return(&pty_count) > (pty_limit -
 			  (fsi->mount_opts.reserve ? 0 : pty_reserve)))
 		goto out;
 
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.