summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranton <anton@openbsd.org>2018-11-10 11:54:03 +0000
committeranton <anton@openbsd.org>2018-11-10 11:54:03 +0000
commitb423aaf0851738d78b8405afca196b84124b09fc (patch)
tree5b0f7c83286743d3109f029ef00caf697730272e
parentfix error message when querying a non-existent table (diff)
downloadwireguard-openbsd-b423aaf0851738d78b8405afca196b84124b09fc.tar.xz
wireguard-openbsd-b423aaf0851738d78b8405afca196b84124b09fc.zip
Conform to POSIX-2001 in which the behavior of passing a negative length using
posix file locks is defined. Also, detect overflows when dealing with positive lengths. ok millert@ visa@
-rw-r--r--lib/libc/sys/fcntl.221
-rw-r--r--sys/kern/vfs_lockf.c17
2 files changed, 29 insertions, 9 deletions
diff --git a/lib/libc/sys/fcntl.2 b/lib/libc/sys/fcntl.2
index a66a9633d01..87ec1d3637a 100644
--- a/lib/libc/sys/fcntl.2
+++ b/lib/libc/sys/fcntl.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: fcntl.2,v 1.31 2014/12/16 00:06:49 schwarze Exp $
+.\" $OpenBSD: fcntl.2,v 1.32 2018/11/10 11:54:03 anton Exp $
.\" $NetBSD: fcntl.2,v 1.6 1995/02/27 12:32:29 cgd Exp $
.\"
.\" Copyright (c) 1983, 1993
@@ -30,7 +30,7 @@
.\"
.\" @(#)fcntl.2 8.2 (Berkeley) 1/12/94
.\"
-.Dd $Mdocdate: December 16 2014 $
+.Dd $Mdocdate: November 10 2018 $
.Dt FCNTL 2
.Os
.Sh NAME
@@ -286,7 +286,11 @@ The value of
is the number of consecutive bytes to be locked.
If
.Fa l_len
-is negative, the result is undefined.
+is negative, the area starting at
+.Fa l_start Ns + Ns Fa l_len
+and ending at
+.Fa l_start Ns -1
+is locked.
The
.Fa l_pid
field is only used with
@@ -509,6 +513,17 @@ or
.Dv F_SETLKW ,
and satisfying the lock or unlock request would result in the
number of locked regions in the system exceeding a system-imposed limit.
+.It Bq Er EOVERFLOW
+The argument
+.Fa cmd
+is
+.Dv F_GETLK ,
+.Dv F_SETLK
+or
+.Dv F_SETLKW
+and the segment length of a file to be locked is too large to be represented by
+an
+.Vt off_t .
.It Bq Er ESRCH
.Fa cmd
is
diff --git a/sys/kern/vfs_lockf.c b/sys/kern/vfs_lockf.c
index 0d1c9891383..6599a480884 100644
--- a/sys/kern/vfs_lockf.c
+++ b/sys/kern/vfs_lockf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_lockf.c,v 1.29 2018/11/02 07:17:34 anton Exp $ */
+/* $OpenBSD: vfs_lockf.c,v 1.30 2018/11/10 11:54:03 anton Exp $ */
/* $NetBSD: vfs_lockf.c,v 1.7 1996/02/04 02:18:21 christos Exp $ */
/*
@@ -235,12 +235,17 @@ lf_advlock(struct lockf **head, off_t size, caddr_t id, int op,
}
if (start < 0)
return (EINVAL);
- if (fl->l_len == 0) {
- end = -1;
- } else {
- end = start + fl->l_len - 1;
- if (end < start)
+ if (fl->l_len > 0) {
+ if (fl->l_len - 1 > LLONG_MAX - start)
+ return (EOVERFLOW);
+ end = start + (fl->l_len - 1);
+ } else if (fl->l_len < 0) {
+ if (fl->l_start + fl->l_len < 0)
return (EINVAL);
+ end = fl->l_start - 1;
+ start += fl->l_len;
+ } else {
+ end = -1;
}
/*