From nobody Fri May 17 03:12:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1598194815; cv=none; d=zohomail.com; s=zohoarc; b=lxe34TXWBoS2Phdg6DZB57p164e4Pyjx25B1Zg3exkvUujr2vshEYby01RucQwY4poOibPEjq/hTqWzvHnt/bzZpHSOoybx2m1LR2/AJvEE8oSZboLttxGdNppRCNVovf6LOMbXX+GUPUAqruliadtKJlgLi0z8GWd793UJDhn8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598194815; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ei57CYmqMgBkRmhif2M0i7fosJgMffqE28HtYbeNmZY=; b=gh8kpltcfNZerouUdWMqYQlzFZWqAXpXj8RLz8p/XKpa4G7ut+6ccI9Vrl9C7R+ZLR7tZO8VSYPpCHMF1w2Vs5WNK/ZKllRUKMC0K0BnJEY4wybWEc46QBUOsK4va4uK9O7zCP58XyKljkLMG8MDJAJDBnMJb88owhfLkRFyblU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598194815333672.9484513318099; Sun, 23 Aug 2020 08:00:15 -0700 (PDT) Received: from localhost ([::1]:38680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9rTh-0006TD-5T for importer@patchew.org; Sun, 23 Aug 2020 11:00:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSq-0004q1-8y for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:20 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:39683) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSo-0006do-JF for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:19 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MF418-1kPJwh0Nr6-00FWNg; Sun, 23 Aug 2020 16:59:15 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 1/6] linux-user: Fix "print_fdset()" in "strace.c" to not print ", " after last value Date: Sun, 23 Aug 2020 16:59:07 +0200 Message-Id: <20200823145912.1171738-2-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200823145912.1171738-1-laurent@vivier.eu> References: <20200823145912.1171738-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:fQMcgnkCFnxaicvpaHt7bUk2jrLc0OM4pV+KWmfeJkkP9th9/bI C6fQgRJtnV/Rb1qJMKmmHGl+wooO4CTHGk7JMsVBGhDzIm+7roVuwx7S133uJTI1e/6XU8W SwKBWdhTTymLgTl6D5XUG2v2XxZmrrp0TF9aub3lHCCUrYE952lGnolDBeja4PlLEXeWzVU 4VOF7zsoUDeu/am2JFjQA== X-UI-Out-Filterresults: notjunk:1;V03:K0:dY4q/t3LkVo=:g5cyiyOzHR2xYXvjbQ0oDT GWdfL+ASgrDN7F1nopAnQVRHr3nY70t2nl6Uf+2ezmh9elwcx7JohPNXiqeVfyvVYJhHNqovx U0P9PNcAL4dJdlo9muJzFk5dvuO8QBSDJVRAnnaie/M8Nrw4dYICHTkv3cELhnt6FlxH2qeAs QQdTJVIHJOuFf9NpMP3DDBKzvHzbjBoTS0z3VRPIvE8od3Mwp/JiiMoPtxuQ8JWjVEBVEUv27 lgfqMTYGISLE/aJ1aP2gVS7MerwM7I8Dzxh8eDmj3h1LMEtl2UPbvuBmztwFSQ3Vr36fmlcrD X6/zY1jL3LPClvjTC5e0tz/ZZf1rt7ctYX5Ibjy29d+u325MNsf9i+EuWp9vhqoWNDG0RaUFS UNw0FYoVQUyZV41+KlxXRBuxDLty2dfJkGppVbLkVoeifKDGcS1nco7BH+/xdm2WJdR3RRwak loemA2yA8arWLrSKX0SFbh8eLgCUMDKGQUonNq6l01q4t74oidNbLWsNINrhFX/mC5+9mcvVr VpYSAUSCSXNuel5BwHlaC/0VBfKTERL8YuiGkCf9Q7sWkugRIAO7+sy5I/aVsF1i+Sdx3dL1l gn/0KZr467rL2WtSEC6FEehk54mOq3+lTgoKbQbpdrLIN9WAzLsW6ytyELvWxFFwdjVTRmgqy saO1Tl7CB/4oBxibLxLtrglUlUIBLJf50MkbJj3zjYQamBNfFP1+J88BVxvjEqS90Y4tFwqEJ gIn3OEhRs+E9yBO/Riuh2IhMbAP5CR/q1DGlNwb/77XKrCaFBq0uEJv4l4qayDB5dPva504Ln K5/pH3hFxrT/zoqyupKLH0/fzAT2/7cf+/I66b23n1S/K5+PpFjXDUvWbXW0ASIYNFyrOaU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=217.72.192.75; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 10:59:17 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Filip Bozuta Function "print_fdset()" in "strace.c" is used to print the file descriptor values in "print__newselect()" which prints arguments of syscall _newselect= (). Until changes from this patch, this function was printing "," even after the last value of the fd_set argument. This was changed in this patch by removi= ng this unnecessary "," after the last fd value and thus improving the estetic= s of the _newselect() "-strace" print. Implementation notes: The printing fix was made possible by using an existing function "get_co= mma()" which returns a "," or an empty string "" based on its argument (0 for "= ," and other for ""). Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200702160915.9517-1-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- linux-user/strace.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index 13981341b327..5e380486433c 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -541,6 +541,7 @@ static void print_fdset(int n, abi_ulong target_fds_addr) { int i; + int first =3D 1; =20 qemu_log("["); if( target_fds_addr ) { @@ -555,9 +556,12 @@ print_fdset(int n, abi_ulong target_fds_addr) return; =20 for (i=3Dn; i>=3D0; i--) { - if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_= ABI_BITS - 1))) & 1) - qemu_log("%d,", i); + if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> + (i & (TARGET_ABI_BITS - 1))) & 1) { + qemu_log("%s%d", get_comma(first), i); + first =3D 0; } + } unlock_user(target_fds, target_fds_addr, 0); } qemu_log("]"); --=20 2.26.2 From nobody Fri May 17 03:12:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1598194816; cv=none; d=zohomail.com; s=zohoarc; b=jklk/9eAYBI00Ap7EEuvPSRJbF4cnQ1EBonYQdWO3hV07jwsRM6EkuonOx8nb9zLgF3SA8l92PmtvYBfk04r+Hjhw8eKX809PQL+zulR8J9tEg5Ps4xSucIEP7e9HXiodYHk7tGsohj/Y99km5WOULNyWU/jXgSZlHlVC/kalNA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598194816; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JiEkVxcOfuMktQAh35q+WwnwzNzBhoyR5assqUVwYxs=; b=epksIhzPQqbvgqSAVN9YFWkESJ7aaXHtVnqs4nilH4++43PAcJ9aO6AH7OegkbUsCyPO7CdLfDx0GLDHaa2T+n4FNe6qoDNwwL2epF82PctSyAnsq6HT6eBX7oDj5IfhiK+NsYYYf9iLFKSBY/XSeIIsfEwbPKGxvwejpwTA8s4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598194816631461.3443245705438; Sun, 23 Aug 2020 08:00:16 -0700 (PDT) Received: from localhost ([::1]:38800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9rTi-0006W4-2y for importer@patchew.org; Sun, 23 Aug 2020 11:00:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSr-0004rM-Rs for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:21 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:40005) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSp-0006dq-Ap for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:21 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N18I8-1kbt0r2bl4-012W6Y; Sun, 23 Aug 2020 16:59:15 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 2/6] linux-user: Validate mmap/mprotect prot value Date: Sun, 23 Aug 2020 16:59:08 +0200 Message-Id: <20200823145912.1171738-3-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200823145912.1171738-1-laurent@vivier.eu> References: <20200823145912.1171738-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:Go7dNnmGWvrNwcfNOSZtXSLggfMJP+pnuQ1MiqldJQLatJdV5Bp 7rod3jpuAIgYINDwB9/9/yNwXCHC/F0QcZCVXmV6RL2cbV3Yne9fEygttjz87Y6kJuo8zQT Cs7vdmrV5JZu+oPHg2kiCF2RQy1B8bzs8Lr1BstahPjIv0EtVMAB528wnjxAdErGcbUIttN cL5I2OcKKFI8/DYhX4WUA== X-UI-Out-Filterresults: notjunk:1;V03:K0:/wutq+zkr2A=:ex7dAghrSnrnQAjeiAe10v U5dlOgNLBo2EAGR6IpPx7j06p9DF5u3d/d37YkuJU1JryH9qcufAvSO6Et294Tjb8bjyul1aV QNeU4e+3wmssnUopNixLT5u0MvU720AkVx+X6HSQnq1VHLKpPttEVeb47BBePOtO7rAI4ElGQ 6DCmR2G8u4r1dh5z6S3dnC5DQBegEe6mmvhjmnnoVB9pYUxlW5MJ5GGluNUYlJpS6Spiti0dc C/TueLKsLCeYynGnXkflhiU2umHMNtuxl+LfKckBSbjLaEfsUW2g1jw9lJOcnU3QG8wSMCT1t 8xV4v3oiU7BDMYcP6Q/H7gMWQcwZdh3J/R+mp4vNEXF87Lf1dgFweYs2ULFBOBgZlsS3nh6HI fXiFHHKErkNPNnyGXxkQryQBs9DO3RmeFX0sdlyvXKIxrsELPZcKhM9p8LfoyOPJgEG5n+dNF F5zzqsZHX3VDB9zPc9d7gZ+sitZHIO1/3b5YX0J7F3r7JBxcU7Z+alYOl2a3G6NBMphJ7nPVV eG3x/dl/eVMGEgmiU+S5EHIPxcSKJVNyiBN3U+SbxYlOXH3BLdh/7RGUMY6TOPg8indZSLelO 2V05tVymVR0t9uMLwntgEqipRyxpkoSfHFnueTSXLLufRwKV910Zlp6iGMtyfydobggvp43Cg FilZg2LiWfz0PgIXb5pQ4SLGb6XVDvrmhpvk7ljL9HU2Zhjs+yJnLEMhANLmIuOLuFfxfOF97 evy8l7BtevQhTwVrSYoz59MYORFafFh0cY1UfUG3hW+j3vFk2pbrRCR2CbImXFR3NTCOm9gNt gPtV8iij/kGvfetkGQFfxvn+RBi8yq/3/ICscxYP70rSDHFRUCdqgIl7mSt//l+gqcB9r/4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=217.72.192.74; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 10:59:17 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Richard Henderson The kernel will return -EINVAL for bits set in the prot argument that are unknown or invalid. Previously we were simply cropping out the bits that we care about. Introduce validate_prot_to_pageflags to perform this check in a single place between the two syscalls. Differentiate between the target and host versions of prot. Compute the qemu internal page_flags value at the same time. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Message-Id: <20200519185645.3915-2-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/mmap.c | 106 +++++++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 33 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 0019447892e0..46c7eeba9bd2 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -59,64 +59,96 @@ void mmap_fork_end(int child) pthread_mutex_unlock(&mmap_mutex); } =20 +/* + * Validate target prot bitmask. + * Return the prot bitmask for the host in *HOST_PROT. + * Return 0 if the target prot bitmask is invalid, otherwise + * the internal qemu page_flags (which will include PAGE_VALID). + */ +static int validate_prot_to_pageflags(int *host_prot, int prot) +{ + int valid =3D PROT_READ | PROT_WRITE | PROT_EXEC | TARGET_PROT_SEM; + int page_flags =3D (prot & PAGE_BITS) | PAGE_VALID; + + /* + * For the host, we need not pass anything except read/write/exec. + * While PROT_SEM is allowed by all hosts, it is also ignored, so + * don't bother transforming guest bit to host bit. Any other + * target-specific prot bits will not be understood by the host + * and will need to be encoded into page_flags for qemu emulation. + */ + *host_prot =3D prot & (PROT_READ | PROT_WRITE | PROT_EXEC); + + return prot & ~valid ? 0 : page_flags; +} + /* NOTE: all the constants are the HOST ones, but addresses are target. */ -int target_mprotect(abi_ulong start, abi_ulong len, int prot) +int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) { abi_ulong end, host_start, host_end, addr; - int prot1, ret; + int prot1, ret, page_flags, host_prot; =20 - trace_target_mprotect(start, len, prot); + trace_target_mprotect(start, len, target_prot); =20 - if ((start & ~TARGET_PAGE_MASK) !=3D 0) + if ((start & ~TARGET_PAGE_MASK) !=3D 0) { return -TARGET_EINVAL; + } + page_flags =3D validate_prot_to_pageflags(&host_prot, target_prot); + if (!page_flags) { + return -TARGET_EINVAL; + } len =3D TARGET_PAGE_ALIGN(len); end =3D start + len; if (!guest_range_valid(start, len)) { return -TARGET_ENOMEM; } - prot &=3D PROT_READ | PROT_WRITE | PROT_EXEC; - if (len =3D=3D 0) + if (len =3D=3D 0) { return 0; + } =20 mmap_lock(); host_start =3D start & qemu_host_page_mask; host_end =3D HOST_PAGE_ALIGN(end); if (start > host_start) { /* handle host page containing start */ - prot1 =3D prot; - for(addr =3D host_start; addr < start; addr +=3D TARGET_PAGE_SIZE)= { + prot1 =3D host_prot; + for (addr =3D host_start; addr < start; addr +=3D TARGET_PAGE_SIZE= ) { prot1 |=3D page_get_flags(addr); } if (host_end =3D=3D host_start + qemu_host_page_size) { - for(addr =3D end; addr < host_end; addr +=3D TARGET_PAGE_SIZE)= { + for (addr =3D end; addr < host_end; addr +=3D TARGET_PAGE_SIZE= ) { prot1 |=3D page_get_flags(addr); } end =3D host_end; } - ret =3D mprotect(g2h(host_start), qemu_host_page_size, prot1 & PAG= E_BITS); - if (ret !=3D 0) + ret =3D mprotect(g2h(host_start), qemu_host_page_size, + prot1 & PAGE_BITS); + if (ret !=3D 0) { goto error; + } host_start +=3D qemu_host_page_size; } if (end < host_end) { - prot1 =3D prot; - for(addr =3D end; addr < host_end; addr +=3D TARGET_PAGE_SIZE) { + prot1 =3D host_prot; + for (addr =3D end; addr < host_end; addr +=3D TARGET_PAGE_SIZE) { prot1 |=3D page_get_flags(addr); } - ret =3D mprotect(g2h(host_end - qemu_host_page_size), qemu_host_pa= ge_size, - prot1 & PAGE_BITS); - if (ret !=3D 0) + ret =3D mprotect(g2h(host_end - qemu_host_page_size), + qemu_host_page_size, prot1 & PAGE_BITS); + if (ret !=3D 0) { goto error; + } host_end -=3D qemu_host_page_size; } =20 /* handle the pages in the middle */ if (host_start < host_end) { - ret =3D mprotect(g2h(host_start), host_end - host_start, prot); - if (ret !=3D 0) + ret =3D mprotect(g2h(host_start), host_end - host_start, host_prot= ); + if (ret !=3D 0) { goto error; + } } - page_set_flags(start, start + len, prot | PAGE_VALID); + page_set_flags(start, start + len, page_flags); mmap_unlock(); return 0; error: @@ -360,19 +392,26 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong si= ze, abi_ulong align) } =20 /* NOTE: all the constants are the HOST ones */ -abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, +abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, int flags, int fd, abi_ulong offset) { abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_l= en; + int page_flags, host_prot; =20 mmap_lock(); - trace_target_mmap(start, len, prot, flags, fd, offset); + trace_target_mmap(start, len, target_prot, flags, fd, offset); =20 if (!len) { errno =3D EINVAL; goto fail; } =20 + page_flags =3D validate_prot_to_pageflags(&host_prot, target_prot); + if (!page_flags) { + errno =3D EINVAL; + goto fail; + } + /* Also check for overflows... */ len =3D TARGET_PAGE_ALIGN(len); if (!len) { @@ -438,14 +477,15 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, /* Note: we prefer to control the mapping address. It is especially important if qemu_host_page_size > qemu_real_host_page_size */ - p =3D mmap(g2h(start), host_len, prot, + p =3D mmap(g2h(start), host_len, host_prot, flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0); - if (p =3D=3D MAP_FAILED) + if (p =3D=3D MAP_FAILED) { goto fail; + } /* update start so that it points to the file position at 'offset'= */ host_start =3D (unsigned long)p; if (!(flags & MAP_ANONYMOUS)) { - p =3D mmap(g2h(start), len, prot, + p =3D mmap(g2h(start), len, host_prot, flags | MAP_FIXED, fd, host_offset); if (p =3D=3D MAP_FAILED) { munmap(g2h(start), host_len); @@ -479,19 +519,19 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, /* msync() won't work here, so we return an error if write is possible while it is a shared mapping */ if ((flags & MAP_TYPE) =3D=3D MAP_SHARED && - (prot & PROT_WRITE)) { + (host_prot & PROT_WRITE)) { errno =3D EINVAL; goto fail; } - retaddr =3D target_mmap(start, len, prot | PROT_WRITE, + retaddr =3D target_mmap(start, len, target_prot | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (retaddr =3D=3D -1) goto fail; if (pread(fd, g2h(start), len, offset) =3D=3D -1) goto fail; - if (!(prot & PROT_WRITE)) { - ret =3D target_mprotect(start, len, prot); + if (!(host_prot & PROT_WRITE)) { + ret =3D target_mprotect(start, len, target_prot); assert(ret =3D=3D 0); } goto the_end; @@ -502,13 +542,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, if (real_end =3D=3D real_start + qemu_host_page_size) { /* one single host page */ ret =3D mmap_frag(real_start, start, end, - prot, flags, fd, offset); + host_prot, flags, fd, offset); if (ret =3D=3D -1) goto fail; goto the_end1; } ret =3D mmap_frag(real_start, start, real_start + qemu_host_pa= ge_size, - prot, flags, fd, offset); + host_prot, flags, fd, offset); if (ret =3D=3D -1) goto fail; real_start +=3D qemu_host_page_size; @@ -517,7 +557,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, if (end < real_end) { ret =3D mmap_frag(real_end - qemu_host_page_size, real_end - qemu_host_page_size, end, - prot, flags, fd, + host_prot, flags, fd, offset + real_end - qemu_host_page_size - star= t); if (ret =3D=3D -1) goto fail; @@ -533,13 +573,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, else offset1 =3D offset + real_start - start; p =3D mmap(g2h(real_start), real_end - real_start, - prot, flags, fd, offset1); + host_prot, flags, fd, offset1); if (p =3D=3D MAP_FAILED) goto fail; } } the_end1: - page_set_flags(start, start + len, prot | PAGE_VALID); + page_set_flags(start, start + len, page_flags); the_end: trace_target_mmap_complete(start); if (qemu_loglevel_mask(CPU_LOG_PAGE)) { --=20 2.26.2 From nobody Fri May 17 03:12:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1598194816; cv=none; d=zohomail.com; s=zohoarc; b=FCeFq3fcVZ9siejfu/1YP1MlPUU+7a+Djz9sp97d8lgQvchJN0HKN2y+aQPaYWv57m+hOcvr8HCmWKWysMxrP288BreKPaMcKOa+03hOo0M10gS0LRTsCpO1u/e136/ztR/o4vRRUaRO8SMEDJ1OrREmOIvtf021pLxrrc0A8wA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598194816; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wur1SFGp5xDijZMn7bJkUj1KQAmzkSNHK88wQEnF7jk=; b=SQIJ551DxF6iRPxmaBPyjSwu0nd7hgA+M2qukgJvRKBAu/PoSUT9TByn1jA65utjHcb8r9KIYh/WoxYXdcTOaymWHmNsCOZeT1tkgNO9VQi7deB3SeYPNq6Pt5LQF0SbyftF29pRJSlEwQAK6L0IaVH6LAUuu2e6+w8jNSl5HGc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598194816710251.9729152170711; Sun, 23 Aug 2020 08:00:16 -0700 (PDT) Received: from localhost ([::1]:38852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9rTj-0006XS-C5 for importer@patchew.org; Sun, 23 Aug 2020 11:00:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSr-0004r1-HD for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:21 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:52415) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSp-0006dz-PQ for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:21 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MrgcU-1kxGiW1FZ6-00nljk; Sun, 23 Aug 2020 16:59:16 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 3/6] linux-user: Adjust guest page protection for the host Date: Sun, 23 Aug 2020 16:59:09 +0200 Message-Id: <20200823145912.1171738-4-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200823145912.1171738-1-laurent@vivier.eu> References: <20200823145912.1171738-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:uVSC+BN8iffnkVovJ5et5KG/MimAMbh6ytMx2N7MYhuKxwm2lXf pm5282ABPtW5oxmMgi8dvLGg1PHoCBh7R9znGic0L6LkcjmsD7cP0i998jpvA9vM43rDp8m JWTsw1dGeO4sD83jxN9m3iJJDSDodXoDjPEv0n3TLlAWSHCNjM7JDF0NozNvdcJNDr0kOi/ oDB4YsaeOXMh4iPgQObnA== X-UI-Out-Filterresults: notjunk:1;V03:K0:+930OTmX7ew=:8+r9hGeTbX+k/Jokb28Vju 1WkyEYFeX/sgS41Z8vCpUedbsFB67c5ffe27pzM/1R21p9TlBWPE5Zw5kTgu1lbW7mnUoG0Zr QZZrazNnfOdhYj9mK6cxXClavvpJuBWinxIyhAQMvNI1FFIQq0sGQKjGJpVA/ye5oVN5ga8X3 GLU/hQ2BpfXUU9twhnGgy5g7GVJ201N/JvjDCfK+oeGiVpknnfmbjO8s3IgiavRTzd5OF83bF q522eFKL8FljtGwr/NcceQhrVflAYd/SSBVt4RKgum7Q/Gs4LG7rGpwY4SN7BExSJMKyHptcN 2h+2GYrNXeJ0l6QdOhTYikltVlk0d/ePaTqaV9iw6FRkwOvttnuO733D8+fS4mGDsN9AKSjTu RaC/iKJQl8myWOCSu587DVMX+JnCfVBeP9mZipcelC/u4ZBYqQ/X9kP4+QeEri/n3J9UkqgDI dA1dKcWqke0siqB7SsKZgLGimX90e4r32lFTMBrhaIM1s9F2iKlM5g+w7qxG2TXKn1hLDA3R1 Vl0/OkYIbSO5NN/QZAcXTw1+dpxtt1m1+xQNeez/wsAdMXnBxeC5kP3g8RkoJDoyMsnjUXvUC bxqvgs0QNSgQx+0r6GTlJh6AgFvYlHz1BKw5Ixyn/3zGtcX4KxpfJ/BBGGirbvbtzBIW9F0b8 3dals+rooEVUAS7G5rLzuvynzXkDRTCmyl7fi4KMBCkBcYSbqCVOzYfXPWG05qjCDKrqsw9ET D96FpSUc2ufv0d0Y79al93nJgsuqPybMeYBqGl1e7/IbK6pnIXCMAOC4sdSQhRNWWjyq+Zhjr eYHeeakIbNpQYj1gIesn8TcMWo4e2BJJYKxFmb5yHMtCdYOKZAhsy8kEOSCyIpqIb4pC+m6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=212.227.17.13; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 10:59:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Richard Henderson , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Executable guest pages are never directly executed by the host, but do need to be readable for translation. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Maydell Message-Id: <20200519185645.3915-3-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/mmap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 46c7eeba9bd2..f2615634201d 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -76,8 +76,12 @@ static int validate_prot_to_pageflags(int *host_prot, in= t prot) * don't bother transforming guest bit to host bit. Any other * target-specific prot bits will not be understood by the host * and will need to be encoded into page_flags for qemu emulation. + * + * Pages that are executable by the guest will never be executed + * by the host, but the host will need to be able to read them. */ - *host_prot =3D prot & (PROT_READ | PROT_WRITE | PROT_EXEC); + *host_prot =3D (prot & (PROT_READ | PROT_WRITE)) + | (prot & PROT_EXEC ? PROT_READ : 0); =20 return prot & ~valid ? 0 : page_flags; } --=20 2.26.2 From nobody Fri May 17 03:12:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1598195004; cv=none; d=zohomail.com; s=zohoarc; b=FiZyk7ZuqZ48z9cVVsHWGG9Olsr4Huz/bF6b+E/b0mtcyo+B3SReKpcegmRbBkj9O3XS6XQtDNoyFPpiCBDFpEfk1LFwbtx2A+ev4tqRW/72t+yjzTgi//wA7QK1a0qlsddt+uV8MtzQEGB8rzS/+bm/bxSvZhxMvX0BijXl8gA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598195004; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5cuv+qOzDbM1oZ6x+D57dKd0KZk7AYrYOwmjHCy0D/M=; b=BihAV6TVM4V78E5aZWccWAFEJzf5fhdIxcmokAr+BupQbyoYs0juO2xBUimm23W+JpuzL26XaXf1bxjg9780ux3UXsSUZx/MTCqdEYA3zODNQBE+SonxoQmHUmIZyEwClUz0QePt8vQ2L+ORgplF77AhmfOkXjKGMaAl4q84vms= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598195004001969.6672253546375; Sun, 23 Aug 2020 08:03:24 -0700 (PDT) Received: from localhost ([::1]:50024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9rWk-0002xL-PZ for importer@patchew.org; Sun, 23 Aug 2020 11:03:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSt-0004sx-7u for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:23 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:60059) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSp-0006dr-Bo for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:22 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1M7rxE-1kDjLq3A02-0052nm; Sun, 23 Aug 2020 16:59:16 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 4/6] linux-user: Modify 'target_to_host/host_to_target_itimerspec()' Date: Sun, 23 Aug 2020 16:59:10 +0200 Message-Id: <20200823145912.1171738-5-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200823145912.1171738-1-laurent@vivier.eu> References: <20200823145912.1171738-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:qzRTM4JadDYb+V6mlA5gjbKDsZO7qiQWhJaSMJ2yYYRnK5JDHFA UAQh8ycIyiOi0ZAVCQGkEDPEShUFhSlq9Itrye8gggZgaA1yH5bEEkJpWXszAbY0gOzYCy3 uca5QnApIwPLyhZESLfHd9SGe/8sTiFZ8AK8mg0wCIC8DN0pTynwKCJyw8l9EVUv5i59Dew qNMUdSaUvVD2pi9aNC7fQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:yymeIl/U/Pk=:kaRXpyWuYUpDCSt+1AO4gU omIz47GLNqI2rjacaGaJa8CEqOJQTB8uv0xgbdbDPnb/De3hnoVq++EgpUR0kwEaSpy/hA2d+ D+8Za1KR3V6IK0YMsPueFk3iK30CsDe/RFTgSFXuMtDRAwsVsqULIyGv3oG56pQytsD1/B4cD F3HKpWefrZV270q9or44mmjoUvEPH+iVb9Z1yo4aO+cjOF3EGbEM3AEjnwTqA8540g3PsB4tb gR7GRiAy6aU2tE76uK/t9T/UBK8WPmRUzq+nPRAhYM3vDQ3xaR/QwfyWhu1u8GVOhm35L+s2U bU2OPCxUKSy5vbZuzevP2/eDo5fdthLFdqZ9T+ZA20o6WMT35gfKxTH15aBn4LAgbNZyGAGze zn0SUBaGN5PEIuBEo2ApaRMK26QOUmUydzg9tOsQfS+JhznyA6yLiETXZZIbNrWZam7hqBhnQ mjIQI82jT3dwoLPgfbTcTOYWOLCqcUfgIA+gu9ILwIl5vNYfm8ym6DkCyeFHmrb+yW2i/XkLi 136W1AKiRVuvtUFIuR1TaLFDJZlozyznYZBWVWBvDrMtAUz2NiDWmNBHaHKg9Ej3zXfat2XsC q/Pywn9xEp87RztkKDMVt87QNOHHf0KDB8vJmw9uq4lAFIcj+wF5RWVIv2TA8RakLiG93SjrN WQ8IfF1y9qVXDPeW/0RnGhm3wFbvU2cLikuBLXP/SSuaAQYjdLlxWJpCF1m+5+H/B6PNSZn1G SpGHkzeF9Wkiyf39R2thvxXvXglP0lNFWtsPCa0uC1gNPFH2h4d4yi5slKrcqFFCGrF4Yg44o ecgX/fYjY6nIIWeNpZapXuA3k6CnCy8+MzjJLrI4b2+uEikEBe6i984hAIH8lonqY3bP2qX Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=212.227.17.13; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 10:59:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Filip Bozuta Functions 'target_to_host_itimerspec()' and 'host_to_target_itimerspec()' are used to convert values of type 'struct itimerspec' between target and host. This type has 'struct timespec' as its fields. That is the reason why this patch introduces a little modification to the converting functions to be implemented using already existing functions that convert 'struct tim= espec': 'target_to_host_timespec()' and 'host_to_target_timespec()'. This makes the code of 'target_to_host_itimerspec()' and 'host_to_target_itimerspec()' more clean and readable. Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200722153421.295411-2-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 46 ++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 945fc252791c..aea1160804a2 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1229,7 +1229,9 @@ static inline abi_long copy_to_user_timeval64(abi_ulo= ng target_tv_addr, defined(TARGET_NR_nanosleep) || defined(TARGET_NR_clock_settime) || \ defined(TARGET_NR_utimensat) || defined(TARGET_NR_mq_timedsend) || \ defined(TARGET_NR_mq_timedreceive) || defined(TARGET_NR_ipc) || \ - defined(TARGET_NR_semop) || defined(TARGET_NR_semtimedop) + defined(TARGET_NR_semop) || defined(TARGET_NR_semtimedop) || \ + defined(TARGET_NR_timer_settime) || \ + (defined(TARGET_NR_timerfd_settime) && defined(CONFIG_TIMERFD)) static inline abi_long target_to_host_timespec(struct timespec *host_ts, abi_ulong target_addr) { @@ -6783,46 +6785,36 @@ static inline abi_long target_ftruncate64(void *cpu= _env, abi_long arg1, =20 #if defined(TARGET_NR_timer_settime) || \ (defined(TARGET_NR_timerfd_settime) && defined(CONFIG_TIMERFD)) -static inline abi_long target_to_host_itimerspec(struct itimerspec *host_i= tspec, +static inline abi_long target_to_host_itimerspec(struct itimerspec *host_i= ts, abi_ulong target_addr) { - struct target_itimerspec *target_itspec; - - if (!lock_user_struct(VERIFY_READ, target_itspec, target_addr, 1)) { + if (target_to_host_timespec(&host_its->it_interval, target_addr + + offsetof(struct target_itimerspec, + it_interval)) || + target_to_host_timespec(&host_its->it_value, target_addr + + offsetof(struct target_itimerspec, + it_value))) { return -TARGET_EFAULT; } =20 - host_itspec->it_interval.tv_sec =3D - tswapal(target_itspec->it_interval.tv_sec); - host_itspec->it_interval.tv_nsec =3D - tswapal(target_itspec->it_interval.tv_nsec); - host_itspec->it_value.tv_sec =3D tswapal(target_itspec->it_value.tv_se= c); - host_itspec->it_value.tv_nsec =3D tswapal(target_itspec->it_value.tv_n= sec); - - unlock_user_struct(target_itspec, target_addr, 1); return 0; } #endif =20 #if ((defined(TARGET_NR_timerfd_gettime) || \ defined(TARGET_NR_timerfd_settime)) && defined(CONFIG_TIMERFD)) || \ - defined(TARGET_NR_timer_gettime) || defined(TARGET_NR_timer_settime) + defined(TARGET_NR_timer_gettime) || defined(TARGET_NR_timer_settime) static inline abi_long host_to_target_itimerspec(abi_ulong target_addr, - struct itimerspec *host_its) -{ - struct target_itimerspec *target_itspec; - - if (!lock_user_struct(VERIFY_WRITE, target_itspec, target_addr, 0)) { + struct itimerspec *host_i= ts) +{ + if (host_to_target_timespec(target_addr + offsetof(struct target_itime= rspec, + it_interval), + &host_its->it_interval) || + host_to_target_timespec(target_addr + offsetof(struct target_itime= rspec, + it_value), + &host_its->it_value)) { return -TARGET_EFAULT; } - - target_itspec->it_interval.tv_sec =3D tswapal(host_its->it_interval.tv= _sec); - target_itspec->it_interval.tv_nsec =3D tswapal(host_its->it_interval.t= v_nsec); - - target_itspec->it_value.tv_sec =3D tswapal(host_its->it_value.tv_sec); - target_itspec->it_value.tv_nsec =3D tswapal(host_its->it_value.tv_nsec= ); - - unlock_user_struct(target_itspec, target_addr, 0); return 0; } #endif --=20 2.26.2 From nobody Fri May 17 03:12:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1598194917; cv=none; d=zohomail.com; s=zohoarc; b=Qc4hBltF4r65StYYWLF4ByQRyj+1JBofZ7e0OhtsU6FVKG0iYpIqaadKOoxl1/1JVmOEjMyjJtRnngHWOcoIyJWYEmVC+2An0DE3+Qd9Pkdets9+VmZZo+44RJ+94DpCuRwDQ0poliHAEita+SsargEaiI7oQaZECquduUd3UY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598194917; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N5uCHe2Kpf4srQoqFqrW/C4gieg1uq22V3Jb8LypjZ4=; b=ly2NkLM1907zOftTCTEmyHIuYpO+ePOIR4Mype2NHZs9Moy0H5OkhTDA+qedR7SDafifQgLTExn6uqlQopxz2+IphLJ619Ctf0EY5VtRBjctIFjo45GIOLQvio+tJi1Gthb4Wa0Hg8+LuWKYE9gBKRjwxW6x5VQYmr/q3EOC4lk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598194917061483.3237851251105; Sun, 23 Aug 2020 08:01:57 -0700 (PDT) Received: from localhost ([::1]:45910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9rVL-00019q-Pa for importer@patchew.org; Sun, 23 Aug 2020 11:01:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSs-0004re-5g for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:22 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:51113) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSp-0006dy-Oo for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:21 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MBV6n-1kLjAo0vkd-00D24x; Sun, 23 Aug 2020 16:59:17 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 5/6] linux-user: Add support for a group of 2038 safe syscalls Date: Sun, 23 Aug 2020 16:59:11 +0200 Message-Id: <20200823145912.1171738-6-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200823145912.1171738-1-laurent@vivier.eu> References: <20200823145912.1171738-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:v/JmIcn/3gVAHzsA1rNfUefu5YhhsxT8oo0s52LsPvme60BSJxl W4tKmN3tSlrZj4bdLxt1X9g6Pb0arUJiFb/X9sSU5TlkxiR6N1zVAcb1+tegRgYSQ+0qfAv 7LPvt6Ecntzdm7I8uBGFExthaNHCC3XqavvTPz2Wf/pMbOBGfy4qpt0COXi1Imt3zuAoxLf 64jtSGS1ooICij8nM/iCA== X-UI-Out-Filterresults: notjunk:1;V03:K0:t7GN+OD/ZlQ=:vpH4QomBu6+qsKavJRGm4w ghvkmbHIo9Fuyv0JbUYCm/PHZXapCf+TGXxPUHCDIs21m8RAkZ/dk5Pk2m5v08U+xbdqyzi4v 4CBnX+aGSO1JwfIvJLopqG7yr0ZyQtOCJyg3FfOJKCYWOY/FAyRwQUh5+zejnRacR/g6/5w6y a5CXoiVyHjJwu01SZv0DfmaEd1gOcb9l6B/MDpCozOL/DJGCa7upj4H+xP/T7sba4HmZrhHP0 A0M5zUwPInfLCaqDfXvHp/vAdxvlbVuj47/YMg03KYUqvuP3CEZngLCkO3zJg4IxdRTTqna3/ BPqLs+mmZO2dDfNnLinfrB7RBPXMIDyi1siTaPmQzRoxmrH3oqAJePzDbNM6p37zP+AW5Z+VT ceZfAe1Vx8ZWOSJsx/58HipbNzaSL7nQ9qw/pc/2ScZA3cUXxCNb6ubnfZHyPFKxRV4L/PkRM guvcXVdOX+pv9eXkRJ7E4zHPfVnRA50v2tacLQ7WgDWqV29/bj1hCHxkAt1W7WrnIU1G+U8dc Zjw/pY5i5yW+rmIyCPwOuSTIijMQX0G8c6r3xRQ2ek28HkTIx/KXUgLPwXwG5ISalrPibvvD3 qqASYlNgm4Dff/PvGt32zN984F5/rKCP5uT6kiUFpDqn/QwRNuQgbRrd6PEOUavsFplngLmjh eibsmVpk45kXhqPEWyRQZ6pqmu/W3PHYRPBgPJJCM5BN3VySmoFNJ7mRwEPI0+i3UvuaLEYzV TMNOETjqzksVEySXrM/oZ793Yi52jyTWYWefrYY3QL4Ip2qOb3HnUqV9ZqhIFqVZOahybJnAZ TMgXJTEVj/oFDsxIfXx9F1wtJrbNfJR5VqYPHoJz0ej9TViqlLf89YcNGNMYAZtXBIZiNlF Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=217.72.192.73; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 10:59:18 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Filip Bozuta This patch implements functionality for following time64 syscalls: *clock_getres_time64 This a year 2038 safe variant of syscall: int clock_getres(clockid_t clockid, struct timespec *res) --finding the resoultion of a specified clock-- man page: https://man7.org/linux/man-pages/man2/clock_getres.2.html *timer_gettime64 *timer_settime64 These are year 2038 safe variants of syscalls: int timer_settime(timer_t timerid, int flags, const struct itimerspec *new_value, struct itimerspec *old_value) int timer_gettime(timer_t timerid, struct itimerspec *curr_value) --arming/dissarming and fetching state of POSIX per-process timer-- man page: https://man7.org/linux/man-pages/man2/timer_settime.2.html *timerfd_gettime64 *timerfd_settime64 These are year 2038 safe variants of syscalls: int timerfd_settime(int fd, int flags, const struct itimerspec *new_value, struct itimerspec *old_value) int timerfd_gettime(int fd, struct itimerspec *curr_value) --timers that notify via file descriptor-- man page: https://man7.org/linux/man-pages/man2/timerfd_settime.2.html Implementation notes: Syscall 'clock_getres_time64' was implemented similarly to 'clock_getr= es()'. The only difference was that for the conversion of 'struct timespec' f= rom host to target, function 'host_to_target_timespec64()' was used instea= d of 'host_to_target_timespec()'. For other syscalls, new functions 'host_to_target_itimerspec64()' and 'target_to_host_itimerspec64()' were added to convert the value of the 'struct itimerspec' from host to target and vice versa. A new type 'struct target__kernel_itimerspec' was added in 'syscall_defs.h'. This type was defined with fields which are of the already defined type 'struct target_timespec'. This new 'struct target__kernel_itimerspec' type is used in these new converting functions. These new functions we= re defined similarly to 'host_to_target_itimerspec()' and 'target_to_host= _itimerspec()' the only difference being that 'target_to_host_timespec64()' and 'host_to_target_timespec64()' were used. Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200722153421.295411-3-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 139 +++++++++++++++++++++++++++++++++++++- linux-user/syscall_defs.h | 5 ++ 2 files changed, 143 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index aea1160804a2..bbb61a59c72f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1247,7 +1247,9 @@ static inline abi_long target_to_host_timespec(struct= timespec *host_ts, } #endif =20 -#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) +#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) = || \ + defined(TARGET_NR_timer_settime64) || \ + (defined(TARGET_NR_timerfd_settime64) && defined(CONFIG_TIMERFD)) static inline abi_long target_to_host_timespec64(struct timespec *host_ts, abi_ulong target_addr) { @@ -6801,6 +6803,24 @@ static inline abi_long target_to_host_itimerspec(str= uct itimerspec *host_its, } #endif =20 +#if defined(TARGET_NR_timer_settime64) || \ + (defined(TARGET_NR_timerfd_settime64) && defined(CONFIG_TIMERFD)) +static inline abi_long target_to_host_itimerspec64(struct itimerspec *host= _its, + abi_ulong target_addr) +{ + if (target_to_host_timespec64(&host_its->it_interval, target_addr + + offsetof(struct target__kernel_itimerspe= c, + it_interval)) || + target_to_host_timespec64(&host_its->it_value, target_addr + + offsetof(struct target__kernel_itimerspe= c, + it_value))) { + return -TARGET_EFAULT; + } + + return 0; +} +#endif + #if ((defined(TARGET_NR_timerfd_gettime) || \ defined(TARGET_NR_timerfd_settime)) && defined(CONFIG_TIMERFD)) || \ defined(TARGET_NR_timer_gettime) || defined(TARGET_NR_timer_settime) @@ -6819,6 +6839,26 @@ static inline abi_long host_to_target_itimerspec(abi= _ulong target_addr, } #endif =20 +#if ((defined(TARGET_NR_timerfd_gettime64) || \ + defined(TARGET_NR_timerfd_settime64)) && defined(CONFIG_TIMERFD)) ||= \ + defined(TARGET_NR_timer_gettime64) || defined(TARGET_NR_timer_settim= e64) +static inline abi_long host_to_target_itimerspec64(abi_ulong target_addr, + struct itimerspec *host= _its) +{ + if (host_to_target_timespec64(target_addr + + offsetof(struct target__kernel_itimerspe= c, + it_interval), + &host_its->it_interval) || + host_to_target_timespec64(target_addr + + offsetof(struct target__kernel_itimerspe= c, + it_value), + &host_its->it_value)) { + return -TARGET_EFAULT; + } + return 0; +} +#endif + #if defined(TARGET_NR_adjtimex) || \ (defined(TARGET_NR_clock_adjtime) && defined(CONFIG_CLOCK_ADJTIME)) static inline abi_long target_to_host_timex(struct timex *host_tx, @@ -11811,6 +11851,17 @@ static abi_long do_syscall1(void *cpu_env, int num= , abi_long arg1, return ret; } #endif +#ifdef TARGET_NR_clock_getres_time64 + case TARGET_NR_clock_getres_time64: + { + struct timespec ts; + ret =3D get_errno(clock_getres(arg1, &ts)); + if (!is_error(ret)) { + host_to_target_timespec64(arg2, &ts); + } + return ret; + } +#endif #ifdef TARGET_NR_clock_nanosleep case TARGET_NR_clock_nanosleep: { @@ -12405,6 +12456,32 @@ static abi_long do_syscall1(void *cpu_env, int num= , abi_long arg1, } #endif =20 +#ifdef TARGET_NR_timer_settime64 + case TARGET_NR_timer_settime64: + { + target_timer_t timerid =3D get_timer_id(arg1); + + if (timerid < 0) { + ret =3D timerid; + } else if (arg3 =3D=3D 0) { + ret =3D -TARGET_EINVAL; + } else { + timer_t htimer =3D g_posix_timers[timerid]; + struct itimerspec hspec_new =3D {{0},}, hspec_old =3D {{0},}; + + if (target_to_host_itimerspec64(&hspec_new, arg3)) { + return -TARGET_EFAULT; + } + ret =3D get_errno( + timer_settime(htimer, arg2, &hspec_new, &hspec_o= ld)); + if (arg4 && host_to_target_itimerspec64(arg4, &hspec_old)) { + return -TARGET_EFAULT; + } + } + return ret; + } +#endif + #ifdef TARGET_NR_timer_gettime case TARGET_NR_timer_gettime: { @@ -12428,6 +12505,29 @@ static abi_long do_syscall1(void *cpu_env, int num= , abi_long arg1, } #endif =20 +#ifdef TARGET_NR_timer_gettime64 + case TARGET_NR_timer_gettime64: + { + /* args: timer_t timerid, struct itimerspec64 *curr_value */ + target_timer_t timerid =3D get_timer_id(arg1); + + if (timerid < 0) { + ret =3D timerid; + } else if (!arg2) { + ret =3D -TARGET_EFAULT; + } else { + timer_t htimer =3D g_posix_timers[timerid]; + struct itimerspec hspec; + ret =3D get_errno(timer_gettime(htimer, &hspec)); + + if (host_to_target_itimerspec64(arg2, &hspec)) { + ret =3D -TARGET_EFAULT; + } + } + return ret; + } +#endif + #ifdef TARGET_NR_timer_getoverrun case TARGET_NR_timer_getoverrun: { @@ -12481,6 +12581,20 @@ static abi_long do_syscall1(void *cpu_env, int num= , abi_long arg1, return ret; #endif =20 +#if defined(TARGET_NR_timerfd_gettime64) && defined(CONFIG_TIMERFD) + case TARGET_NR_timerfd_gettime64: + { + struct itimerspec its_curr; + + ret =3D get_errno(timerfd_gettime(arg1, &its_curr)); + + if (arg2 && host_to_target_itimerspec64(arg2, &its_curr)) { + return -TARGET_EFAULT; + } + } + return ret; +#endif + #if defined(TARGET_NR_timerfd_settime) && defined(CONFIG_TIMERFD) case TARGET_NR_timerfd_settime: { @@ -12504,6 +12618,29 @@ static abi_long do_syscall1(void *cpu_env, int num= , abi_long arg1, return ret; #endif =20 +#if defined(TARGET_NR_timerfd_settime64) && defined(CONFIG_TIMERFD) + case TARGET_NR_timerfd_settime64: + { + struct itimerspec its_new, its_old, *p_new; + + if (arg3) { + if (target_to_host_itimerspec64(&its_new, arg3)) { + return -TARGET_EFAULT; + } + p_new =3D &its_new; + } else { + p_new =3D NULL; + } + + ret =3D get_errno(timerfd_settime(arg1, arg2, p_new, &its_old)= ); + + if (arg4 && host_to_target_itimerspec64(arg4, &its_old)) { + return -TARGET_EFAULT; + } + } + return ret; +#endif + #if defined(TARGET_NR_ioprio_get) && defined(__NR_ioprio_get) case TARGET_NR_ioprio_get: return get_errno(ioprio_get(arg1, arg2)); diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 3c261cff0e5e..427a25f5bce5 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -259,6 +259,11 @@ struct target_itimerspec { struct target_timespec it_value; }; =20 +struct target__kernel_itimerspec { + struct target__kernel_timespec it_interval; + struct target__kernel_timespec it_value; +}; + struct target_timex { abi_uint modes; /* Mode selector */ abi_long offset; /* Time offset */ --=20 2.26.2 From nobody Fri May 17 03:12:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1598194916; cv=none; d=zohomail.com; s=zohoarc; b=mLp6Pr0s+lgWyl6SbglxwqDzjdL8Ua2saBzQIa03+X2ySauTgqCZAWETG+QdLOv6vjQ0qFFNG3ucK0UkeacPb6I1ObmreS2fKmPHmGE+6QLvztxENPACz8rEvOn7lqrEamjTPo7lMGE56ENPFj0D5HMU9WXIbQCk+jOPiaf+7iA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598194916; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DF+tId+Wq/TIin3gNmUTWxeVAm0lF/xe0lXnY2kS4As=; b=i2k2gaK801diVKv1bHn43paWVjd9u0kNg+ch2oeuMVb2Q1gMHnt4ofpYfn0Lgzv/NNG33pvMRyPE2+UJmu3aX2Xq5uloG0kixoGkEHVZql0++4649STUaMAbzPUKUQAAct9edzJMmFHiuAd+RH9PCvFz5MsJc3XVsIEE54TnZwo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598194916109852.5781817661821; Sun, 23 Aug 2020 08:01:56 -0700 (PDT) Received: from localhost ([::1]:45852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9rVK-00018I-TS for importer@patchew.org; Sun, 23 Aug 2020 11:01:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSs-0004s2-G3 for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:22 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:51897) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSq-0006eB-7D for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:22 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MJn8J-1juocW3R85-00K4of; Sun, 23 Aug 2020 16:59:18 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 6/6] linux-user: Fix 'utimensat()' implementation Date: Sun, 23 Aug 2020 16:59:12 +0200 Message-Id: <20200823145912.1171738-7-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200823145912.1171738-1-laurent@vivier.eu> References: <20200823145912.1171738-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:n5vp6WaM/sVewsc4RZmh7Lyl7IvAgtl3tE6ukSGIg3/QHihDSIJ MwKaWLhRVKWhbKMVPe/wgFBN2A7OjKsWpxMI2MIRhd9jmjMT8qSbyXGdJ+7HZWCKAcSQC+A 3qTDCIL7gaQ3nxcEUdVlowKcFeSMucHsI1KsOIBpJhLlXtO/QsoO2bfDdDlsUrD8E2E6rmJ WpCl9FkFeng4jRP1/8q+w== X-UI-Out-Filterresults: notjunk:1;V03:K0:eO/moa8BGRk=:dnfDGZAAdOKdLY80ZjTjZ2 lFNu1f1gKl+UnJnQBuEOHDBqg3HUAlYjZzYU23cxU9VwTmLJbEjvddH65kdm5ES7qV6h/Qotc XgLniILwoqT4sG7XTw/1GUV39K8lpr/Twmu0Vkt71bfM0NuV4GqS5of9CXPlpDovHPumEqHqq 2iEOWQ8qGtF9n62lV2mK8zaWFBBF54M0m5VtieiiMuPJnw0gQ9NTp6V8hXKH2Dv6511U2Ehg8 6U7Qry9nM43m4uFr63s+6JXUCFrnJbQpW+vO6fc6PVa6xHhl2HYAu0lI9++lGU4nMiFgRP0YR kL1bMkN7NBceo+g6Wi0UbmW5WpPtKxaRDKdUU42wrRUy+2VLKvnlV1YF8P3vX2Kn9+pYFCzuA A30Z7fUmkXAdi+ON9Y0BbK6jnDN3Zaw+Y1NEtkqsHev147Ukk1Q+fxbtsd/bpzReNKwSctj8t 9dl0PC3u542uPXSHXhf5XSwTQpXgzhDnprJGayi3if3efD3iCdQebe2vSWO6TleniPjRXWDtL KH6quW7TjcoeWSVNuKUFxFRXMObbmXV1A+wtkKwh0vv70iocEHkb46L1lUjqq98eN7/6y0dGw vyMycD+WECBpzkhkQst17OHODyBHxQiJcYuR740DJ2uNfIcexn4vKM0sF5DZEIaMvCDJGDoU5 G31WHIfXkomeYsxNMcC7gXlqOFz9XefB5P5QGexoQTdoBE7whqgC5X2H/rniM2vV814MDjECL bGZljGfi4VGGJoKgilV/+2NOX/4yxJrAm8N4U9bxh7C9+UKWoVKyNoJCCiI2z6RM2ks1/tUFj mTCxzsqh16txGt7tP130T5cjdwTfMLuIxh2oVLFVi3gJHj1cbDwpPRaD1Pz8gGYkTQDLyvH Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=212.227.17.13; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 10:59:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Filip Bozuta Implementation of syscall 'utimensat()' in 'syscall.c' uses functions target_to_host/host_to_target_timespec() to convert values of 'struct timespec' between host and target. However, the implementation doesn't check whether the conversion succeeds and thus can cause an inappropriate error or succeed unappropriately instead of setting errno EFAULT ('Bad address') which is supposed to be set in these cases. This was confirmed with the LTP test for utimensat ('testcases/utimensat') which fails for test cases when the errno EFAULT is expected. After changes from this patch, the test passes for all test cases. Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200811113101.6636-1-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index bbb61a59c72f..b4a7b605f3d4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11919,8 +11919,13 @@ static abi_long do_syscall1(void *cpu_env, int num= , abi_long arg1, if (!arg3) { tsp =3D NULL; } else { - target_to_host_timespec(ts, arg3); - target_to_host_timespec(ts+1, arg3+sizeof(struct target_ti= mespec)); + if (target_to_host_timespec(ts, arg3)) { + return -TARGET_EFAULT; + } + if (target_to_host_timespec(ts + 1, arg3 + + sizeof(struct target_timespec)= )) { + return -TARGET_EFAULT; + } tsp =3D ts; } if (!arg2) --=20 2.26.2