From nobody Fri Jun 17 19:37:36 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id F04F685AA68; Fri, 17 Jun 2022 19:37:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LPq7j3jNDz3Pnl; Fri, 17 Jun 2022 19:37:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494658; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=e0ThDZfJv5SwtEmP58yZJdPAo0aWzc+IiooD8pQq6B8=; b=v9m4h77WU8L80nYGVV6jw7PKi0jSkbLhjZk98lKam+SM26T5b+lKBcXR5ysaWRXji5CQ1Q 6PzAO5lXoH/PPhC/Bo0RmLba6cXr97w4uE500K0DbBFAkksy0DHlBLlZ1DA1fjEH8AVuwP /oQo52+L63mv5/qGF2oP0dqBNI5PWV1sR+XhLKOssJnK1t9lUQPs7NDyr7CtcE3B9x0TrW CObzkZ0V8XhQZ7AIB1i8pm81wx8Tz/FJvzkZ9GZRz+fWB+1pg4nO9AGbDnm74H1Yly3SId RmHi9t44pkZTjgK2ujVhb22Tr6YCIkyFJDtfyyxna77WRxujQBqziR78euMB+A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 23ADA25A33; Fri, 17 Jun 2022 19:37:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25HJbbEV013587; Fri, 17 Jun 2022 19:37:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJbaUU013586; Fri, 17 Jun 2022 19:37:36 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:37:36 GMT Message-Id: <202206171937.25HJbaUU013586@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: df49edfec89c - stable/13 - linux(4): Futex address must be 32-bit aligned. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: df49edfec89c9ab95f636df31b53e247ccc5bfc0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494658; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=e0ThDZfJv5SwtEmP58yZJdPAo0aWzc+IiooD8pQq6B8=; b=OgDSEpybMO4eEkZnsIzP+a3NsAMWBtX6SN9QlVKMQZEUAIB/FlxKzTY3g6ZI5sIJtulOVm Uuki8MQk4ghfC5/84qYRRgbm7mw3AyY0gf4ITHbjC2NSJD+bN0IIvC06kGXxMkfVaLopmF Img5Kp8kEEjjtKvYm9/P0YKwBoj44uYJBIVb7qJIoDI7mo4hXBJhNR5zvCkBQ7r7c3zTsx 9sdqmCmTb3LtSnJRRhv7btHZh2e4wkKwR5bpBik6LtbHIAmmZZ/WAsRyk3wTf5Ck2Gpc18 +JtE978RNp2fq2LFtfpExmEedjTY/s1jR6e7F5l8gNX2Ofb7ZZ7J4GAAMRdaCw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494658; a=rsa-sha256; cv=none; b=buffunHrR3pVKj6vSWLzciBNsl0cHBQkxZOy/L9vlmTNBFL4fegxq4X1ZiGxBwur4Ri3W7 5O0PlURdoB8Bjiww11b/FrTh2+DM8288lG3APxVDr6y/Ch3CM6H0gyqzNWbJcoRzuVn35M Qu9ivLBrjWL5l0T/fQmbVr8HW8m5giIG/ye3e3BLeyZ0jK849TCye9iKkVxxTdaPr3We2q EBDtBpYbyzXaDr5uSb6oMpjwcGsTsQhiRG8RKh+9yEHk7w8Xbi2zhQNXL635CEvzaszB3v JtcSHOQCSSS5c3glRt7NudjAei0caqI8OOj5T4WbR87TuzUXT6HChhTaeZ/jrQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=df49edfec89c9ab95f636df31b53e247ccc5bfc0 commit df49edfec89c9ab95f636df31b53e247ccc5bfc0 Author: Dmitry Chagin AuthorDate: 2021-07-29 09:50:58 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:33:21 +0000 linux(4): Futex address must be 32-bit aligned. Linux futex documentation explicitly states that EINVAL is returned if the futex is not 4-byte aligned. Check futex alignment as a Linux do and return EINVAL. Differential Revision: https://reviews.freebsd.org/D31279 MFC after: 2 weeks (cherry picked from commit dad107705667dfca89db796c1c075a782f4666d4) --- sys/compat/linux/linux_futex.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/sys/compat/linux/linux_futex.c b/sys/compat/linux/linux_futex.c index b002d7281171..c81fe20212a2 100644 --- a/sys/compat/linux/linux_futex.c +++ b/sys/compat/linux/linux_futex.c @@ -125,6 +125,7 @@ struct linux_futex_args { struct timespec kts; }; +static inline int futex_key_get(const void *, int, int, struct umtx_key *); static void linux_umtx_abs_timeout_init(struct umtx_abs_timeout *, struct linux_futex_args *); static int linux_futex(struct thread *, struct linux_futex_args *); @@ -137,6 +138,16 @@ static int linux_futex_unlock_pi(struct thread *, bool, struct linux_futex_args *); static int futex_wake_pi(struct thread *, uint32_t *, bool); +static int +futex_key_get(const void *uaddr, int type, int share, struct umtx_key *key) +{ + + /* Check that futex address is a 32bit aligned. */ + if (!__is_aligned(uaddr, sizeof(uint32_t))) + return (EINVAL); + return (umtx_key_get(uaddr, type, share, key)); +} + int futex_wake(struct thread *td, uint32_t *uaddr, int val, bool shared) { @@ -404,7 +415,7 @@ linux_futex_lock_pi(struct thread *td, bool try, struct linux_futex_args *args) em = em_find(td); uq = td->td_umtxq; - error = umtx_key_get(args->uaddr, TYPE_PI_FUTEX, GET_SHARED(args), + error = futex_key_get(args->uaddr, TYPE_PI_FUTEX, GET_SHARED(args), &uq->uq_key); if (error != 0) return (error); @@ -611,7 +622,7 @@ linux_futex_unlock_pi(struct thread *td, bool rb, struct linux_futex_args *args) if (!rb && (owner & FUTEX_TID_MASK) != em->em_tid) return (EPERM); - error = umtx_key_get(args->uaddr, TYPE_PI_FUTEX, GET_SHARED(args), &key); + error = futex_key_get(args->uaddr, TYPE_PI_FUTEX, GET_SHARED(args), &key); if (error != 0) return (error); umtxq_lock(&key); @@ -661,10 +672,10 @@ linux_futex_wakeop(struct thread *td, struct linux_futex_args *args) if (args->uaddr == args->uaddr2) return (EINVAL); - error = umtx_key_get(args->uaddr, TYPE_FUTEX, GET_SHARED(args), &key); + error = futex_key_get(args->uaddr, TYPE_FUTEX, GET_SHARED(args), &key); if (error != 0) return (error); - error = umtx_key_get(args->uaddr2, TYPE_FUTEX, GET_SHARED(args), &key2); + error = futex_key_get(args->uaddr2, TYPE_FUTEX, GET_SHARED(args), &key2); if (error != 0) { umtx_key_release(&key); return (error); @@ -726,10 +737,10 @@ linux_futex_requeue(struct thread *td, struct linux_futex_args *args) if (nrwake < 0 || nrrequeue < 0) return (EINVAL); - error = umtx_key_get(args->uaddr, TYPE_FUTEX, GET_SHARED(args), &key); + error = futex_key_get(args->uaddr, TYPE_FUTEX, GET_SHARED(args), &key); if (error != 0) return (error); - error = umtx_key_get(args->uaddr2, TYPE_FUTEX, GET_SHARED(args), &key2); + error = futex_key_get(args->uaddr2, TYPE_FUTEX, GET_SHARED(args), &key2); if (error != 0) { umtx_key_release(&key); return (error); @@ -764,7 +775,7 @@ linux_futex_wake(struct thread *td, struct linux_futex_args *args) if (args->val3 == 0) return (EINVAL); - error = umtx_key_get(args->uaddr, TYPE_FUTEX, GET_SHARED(args), &key); + error = futex_key_get(args->uaddr, TYPE_FUTEX, GET_SHARED(args), &key); if (error != 0) return (error); umtxq_lock(&key); @@ -786,7 +797,7 @@ linux_futex_wait(struct thread *td, struct linux_futex_args *args) error = EINVAL; uq = td->td_umtxq; - error = umtx_key_get(args->uaddr, TYPE_FUTEX, GET_SHARED(args), + error = futex_key_get(args->uaddr, TYPE_FUTEX, GET_SHARED(args), &uq->uq_key); if (error != 0) return (error);