Module Name: src Committed By: manu Date: Tue Jul 27 09:32:55 UTC 2021
Modified Files: src/lib/libc/sys: fcntl.2 flock.2 src/share/man/man7: sysctl.7 src/sys/kern: vfs_lockf.c Log Message: Tie the maximum file lock per unprivilegied uid to kern.maxfiles This makes the limit simple to raise at run time. While there, document that fcntl(2) and flock(2) may return ENOMEM when this limit is reached. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/lib/libc/sys/fcntl.2 cvs rdiff -u -r1.22 -r1.23 src/lib/libc/sys/flock.2 cvs rdiff -u -r1.152 -r1.153 src/share/man/man7/sysctl.7 cvs rdiff -u -r1.73 -r1.74 src/sys/kern/vfs_lockf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/sys/fcntl.2 diff -u src/lib/libc/sys/fcntl.2:1.45 src/lib/libc/sys/fcntl.2:1.46 --- src/lib/libc/sys/fcntl.2:1.45 Fri Sep 27 07:20:07 2019 +++ src/lib/libc/sys/fcntl.2 Tue Jul 27 09:32:55 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: fcntl.2,v 1.45 2019/09/27 07:20:07 wiz Exp $ +.\" $NetBSD: fcntl.2,v 1.46 2021/07/27 09:32:55 manu Exp $ .\" .\" Copyright (c) 1983, 1993 .\" The Regents of the University of California. All rights reserved. @@ -549,6 +549,17 @@ The argument is .Dv F_GETPATH and insufficient memory is available. +.Pp +The argument +.Fa cmd +is +.Dv F_GETLK , +.Dv F_SETLK , +or +.Dv F_SETLKW , +and the file lock limit for the current unprivilegied user +has been reached. It can be modifed using sysctl +.Li kern.maxfiles . .It Bq Er ERANGE The argument .Fa cmd Index: src/lib/libc/sys/flock.2 diff -u src/lib/libc/sys/flock.2:1.22 src/lib/libc/sys/flock.2:1.23 --- src/lib/libc/sys/flock.2:1.22 Sat Oct 15 21:35:50 2011 +++ src/lib/libc/sys/flock.2 Tue Jul 27 09:32:55 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: flock.2,v 1.22 2011/10/15 21:35:50 rmind Exp $ +.\" $NetBSD: flock.2,v 1.23 2021/07/27 09:32:55 manu Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -137,6 +137,10 @@ does not include exactly one of .Dv LOCK_SH , or .Dv LOCK_UN . +.It Bq Eq ENOMEM +The file lock limit for the current unprivilegied user +has been reached. It can be modifed using sysctl +.Li kern.maxfiles . .It Bq Er EOPNOTSUPP The argument .Fa fd Index: src/share/man/man7/sysctl.7 diff -u src/share/man/man7/sysctl.7:1.152 src/share/man/man7/sysctl.7:1.153 --- src/share/man/man7/sysctl.7:1.152 Tue Jul 13 16:56:43 2021 +++ src/share/man/man7/sysctl.7 Tue Jul 27 09:32:55 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: sysctl.7,v 1.152 2021/07/13 16:56:43 nia Exp $ +.\" $NetBSD: sysctl.7,v 1.153 2021/07/27 09:32:55 manu Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. @@ -756,6 +756,11 @@ Memory Mapped Files Option is available otherwise\ 0. .It Li kern.maxfiles ( Dv KERN_MAXFILES ) The maximum number of open files that may be open in the system. +This also controls the maximum file locks per unprivilegied user +enforced by +.Xr fnctl 2 +and +.Xr flock 2 . .It Li kern.maxpartitions ( Dv KERN_MAXPARTITIONS ) The maximum number of partitions allowed per disk. .It Li kern.maxlwp Index: src/sys/kern/vfs_lockf.c diff -u src/sys/kern/vfs_lockf.c:1.73 src/sys/kern/vfs_lockf.c:1.74 --- src/sys/kern/vfs_lockf.c:1.73 Mon Jan 31 08:25:32 2011 +++ src/sys/kern/vfs_lockf.c Tue Jul 27 09:32:55 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_lockf.c,v 1.73 2011/01/31 08:25:32 dholland Exp $ */ +/* $NetBSD: vfs_lockf.c,v 1.74 2021/07/27 09:32:55 manu Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_lockf.c,v 1.73 2011/01/31 08:25:32 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_lockf.c,v 1.74 2021/07/27 09:32:55 manu Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -123,7 +123,7 @@ int lockf_debug = 0; * so that the unlock can succeed. If the unlocking causes too many splits, * however, you're totally cutoff. */ -int maxlocksperuid = 1024; +#define MAXLOCKSPERUID (2 * maxfiles) #ifdef LOCKF_DEBUG /* @@ -200,7 +200,7 @@ lf_alloc(int allowfail) uip = uid_find(uid); lcnt = atomic_inc_ulong_nv(&uip->ui_lockcnt); if (uid && allowfail && lcnt > - (allowfail == 1 ? maxlocksperuid : (maxlocksperuid * 2))) { + (allowfail == 1 ? MAXLOCKSPERUID : (MAXLOCKSPERUID * 2))) { atomic_dec_ulong(&uip->ui_lockcnt); return NULL; }