aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Chagin <dchagin@FreeBSD.org>2022-05-09 18:11:37 +0000
committerDmitry Chagin <dchagin@FreeBSD.org>2022-05-09 18:11:37 +0000
commitb17446281d21311cc4f9d522c5d18337a9f786bc (patch)
treebe9f11bb39f524873f079443e6f3728373ae6801
parente76857671873f0c9037dcc9c546b490714096c73 (diff)
downloadsrc-b17446281d21311cc4f9d522c5d18337a9f786bc.tar.gz
src-b17446281d21311cc4f9d522c5d18337a9f786bc.zip
linux(4): Fixed offset miscalculation in the preadv/pwritev syscalls.
MFC after: 2 weeks
-rw-r--r--sys/compat/linux/linux_file.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
index 8926e760fc39..199bed80d92a 100644
--- a/sys/compat/linux/linux_file.c
+++ b/sys/compat/linux/linux_file.c
@@ -1268,6 +1268,15 @@ linux_pwrite(struct thread *td, struct linux_pwrite_args *uap)
return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte, offset));
}
+#define HALF_LONG_BITS ((sizeof(l_long) * NBBY / 2))
+
+static inline off_t
+pos_from_hilo(unsigned long high, unsigned long low)
+{
+
+ return (((off_t)high << HALF_LONG_BITS) << HALF_LONG_BITS) | low;
+}
+
int
linux_preadv(struct thread *td, struct linux_preadv_args *uap)
{
@@ -1280,8 +1289,7 @@ linux_preadv(struct thread *td, struct linux_preadv_args *uap)
* pos_l and pos_h, respectively, contain the
* low order and high order 32 bits of offset.
*/
- offset = (((off_t)uap->pos_h << (sizeof(offset) * 4)) <<
- (sizeof(offset) * 4)) | uap->pos_l;
+ offset = pos_from_hilo(uap->pos_h, uap->pos_l);
if (offset < 0)
return (EINVAL);
#ifdef COMPAT_LINUX32
@@ -1308,8 +1316,7 @@ linux_pwritev(struct thread *td, struct linux_pwritev_args *uap)
* pos_l and pos_h, respectively, contain the
* low order and high order 32 bits of offset.
*/
- offset = (((off_t)uap->pos_h << (sizeof(offset) * 4)) <<
- (sizeof(offset) * 4)) | uap->pos_l;
+ offset = pos_from_hilo(uap->pos_h, uap->pos_l);
if (offset < 0)
return (EINVAL);
#ifdef COMPAT_LINUX32