From patchwork Thu Nov 11 11:05:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 519120 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp112848imj; Thu, 11 Nov 2021 03:09:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbRQNWCfiwimcFT20bJ3EjIySrW9T3EYI8a810aYts5dNxtgQp3/SwgN7uZdeIaPIqHRtD X-Received: by 2002:ab0:22d6:: with SMTP id z22mr9247237uam.65.1636628996137; Thu, 11 Nov 2021 03:09:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636628996; cv=none; d=google.com; s=arc-20160816; b=eUQATeuJsVHF8HYWteeuBAkhd/tWXNAb56MFeYoj4WxHeXESkpRHavtBOtl3QjzXUf 8Bi4ySeZFpVPa2xHeEIzyAinpree19VDq4rB/zWRyJOqWeV48mnrr3S3etxORBiJiLYq f/PFRre2qGtD3FTjI0DyXDIhDEOI8RAlVHLHgs5jMbXxD8bySpf1kO/8Kp7Xph9Zf8Y9 ymRW3/MBDh/CNR2qNb9XT/OeVFNJWVwxOiTGBxjGT+RM5LJ1NNUTH7ZLxSMlS/sVzjgd fbJszaES2YrwK7egWw0aw2dYTRg6OMDXNqjKwQannpQgx7io1fHcXIuIOyMa87M0nGAh v7aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=7adQ3xaAWl8MeDhHmWUR6udInB3sSwwX3E31e9ew/RA=; b=vGcH7bBGKHaxS7hkPCLTYIPqIXGBQBnlI8qXN7KACGu0IYgULC0dL+B4JPWEisu3qg bBl/Pv6TcHwLUDKYI6f54xvVIF/gjJeK0dPDPry80dLffTsVbfM7NZFeYPVJcVs+L8Rj FYkEuzgUGV+m5uz7r2wrzQ72G9OI1XxA5weeH39Q1dCk94Yx+EVHl8cuxeR2NF293bDS 7mt6yDzcO/OQ43SQSi4qZMo51eCTn4fyYK5+oJh9Qt15gV5IYW75LgxJXHCUWsF3o1lp 2InrkwfwV3AdLuEKjx6FFxTJrhAN7C5WM10JZElBirWAxOj96e7S4quhubNcNRGJt+JN AkSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u17si6527056vsk.72.2021.11.11.03.09.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Nov 2021 03:09:56 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:60622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml7xr-0000LZ-Ha for patch@linaro.org; Thu, 11 Nov 2021 06:09:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml7tU-0002Z3-Og for qemu-devel@nongnu.org; Thu, 11 Nov 2021 06:05:24 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:40617) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml7tR-0001Nl-OT for qemu-devel@nongnu.org; Thu, 11 Nov 2021 06:05:24 -0500 Received: from quad ([82.142.28.210]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mzydy-1mX9wh1LR0-00x4XO; Thu, 11 Nov 2021 12:05:09 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 1/4] linux-user: Split out do_getdents, do_getdents64 Date: Thu, 11 Nov 2021 12:05:01 +0100 Message-Id: <20211111110504.1574242-2-laurent@vivier.eu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211111110504.1574242-1-laurent@vivier.eu> References: <20211111110504.1574242-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Nq3TEeO6aofs56PXFfdWqm6mWnsqQ/R7By+xjzm1DNAIdyZRk0P 2zaB/9pIItYxqBzgKV7MGJddhHGPcGSWAxg1S9/JdPmYbkohDQ2Hx1z7IMLFAOgo5HbkX30 0cpKw8BUdvUII+vh0m2q0RY4whjQMpheBBURlzToow0E966MzGYLgXasPwhwbWWerZ8K58v ojvKDO8v4AsZht7HER8yA== X-UI-Out-Filterresults: notjunk:1;V03:K0:JyszdH/37AM=:aBfi8fZ2cXrrJXTviinc5n 3ZzM8YlAqHv74b0W2w4wUrYP6D8ZCPYLikaUc4RtzNsBe+d5DaVSzGGBZahwBJgp+/Tanl1/m 8zoSAYGRWi0eTQR3Oz7md+wmhP7j6MNSr4sKg5jhRQZGi9z36REGmsbdzasyhi/OgZoVZ7D/f ZLKTtuPlgvaUneJc4bGYBBHoMFCrbYzkml27WBUbDE7yHAhUxsDXySPjFayOk/DSgd5GTMovt YsvuNKR7GmaX6tRSq/Hj0fAmpbD7zGKasOUaKBFNup5VxktEc1nabSdkQXKpSepDYa0NzrTp4 OSraTT0/1pyCX2F3xKYaf9Hq/GKgSPt/lR4N8Q47GrbnRPrnA7tqHa2eM47o0T9+d3qLiu8Fx 5t2SPqa5GxMCWrxQSuybbb09fnAlTtZP9B89PYCBowUCj75x0BBdNdulFjehu8Gzpa5ObLqp0 xI06VpD9lomfENyBWWkVysr3SkTVGBJr65OUZq8dwKB7TPTzEBJa73cIgFooNTIRVfjRDUfZr 4OyGNAHupGhx+f21jQv4DTaL3Ey0zJaS85A8dpRM3d0J/0mmBqdtfT0Yw5/SALJUHnaOU/dZY B2yN9lAhNna+rEZU+9rnX9laMWjktb8Po1Y+JIuz6MhylURKMN5f9O7Ydg5T/Xyl1DSDOujBQ WkttRgInwdsUupNCWE2eyLMr8zWETIPTD0muw0Co0MXCaidDdtTR1v/KAy5zgh4rKQlc= Received-SPF: none client-ip=212.227.126.187; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Retain all 3 implementations of getdents for now. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed by: Warner Losh Message-Id: <20211107124845.1174791-2-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 325 +++++++++++++++++++++++-------------------- 1 file changed, 172 insertions(+), 153 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 544f5b662ffe..a2f605dec4ca 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8137,6 +8137,176 @@ static int host_to_target_cpu_mask(const unsigned long *host_mask, return 0; } +#ifdef TARGET_NR_getdents +static int do_getdents(abi_long arg1, abi_long arg2, abi_long arg3) +{ + int ret; + +#ifdef EMULATE_GETDENTS_WITH_GETDENTS +# if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 + struct target_dirent *target_dirp; + struct linux_dirent *dirp; + abi_long count = arg3; + + dirp = g_try_malloc(count); + if (!dirp) { + return -TARGET_ENOMEM; + } + + ret = get_errno(sys_getdents(arg1, dirp, count)); + if (!is_error(ret)) { + struct linux_dirent *de; + struct target_dirent *tde; + int len = ret; + int reclen, treclen; + int count1, tnamelen; + + count1 = 0; + de = dirp; + target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0); + if (!target_dirp) { + return -TARGET_EFAULT; + } + tde = target_dirp; + while (len > 0) { + reclen = de->d_reclen; + tnamelen = reclen - offsetof(struct linux_dirent, d_name); + assert(tnamelen >= 0); + treclen = tnamelen + offsetof(struct target_dirent, d_name); + assert(count1 + treclen <= count); + tde->d_reclen = tswap16(treclen); + tde->d_ino = tswapal(de->d_ino); + tde->d_off = tswapal(de->d_off); + memcpy(tde->d_name, de->d_name, tnamelen); + de = (struct linux_dirent *)((char *)de + reclen); + len -= reclen; + tde = (struct target_dirent *)((char *)tde + treclen); + count1 += treclen; + } + ret = count1; + unlock_user(target_dirp, arg2, ret); + } + g_free(dirp); +# else + struct linux_dirent *dirp; + abi_long count = arg3; + + dirp = lock_user(VERIFY_WRITE, arg2, count, 0); + if (!dirp) { + return -TARGET_EFAULT; + } + ret = get_errno(sys_getdents(arg1, dirp, count)); + if (!is_error(ret)) { + struct linux_dirent *de; + int len = ret; + int reclen; + de = dirp; + while (len > 0) { + reclen = de->d_reclen; + if (reclen > len) { + break; + } + de->d_reclen = tswap16(reclen); + tswapls(&de->d_ino); + tswapls(&de->d_off); + de = (struct linux_dirent *)((char *)de + reclen); + len -= reclen; + } + } + unlock_user(dirp, arg2, ret); +# endif +#else + /* Implement getdents in terms of getdents64 */ + struct linux_dirent64 *dirp; + abi_long count = arg3; + + dirp = lock_user(VERIFY_WRITE, arg2, count, 0); + if (!dirp) { + return -TARGET_EFAULT; + } + ret = get_errno(sys_getdents64(arg1, dirp, count)); + if (!is_error(ret)) { + /* + * Convert the dirent64 structs to target dirent. We do this + * in-place, since we can guarantee that a target_dirent is no + * larger than a dirent64; however this means we have to be + * careful to read everything before writing in the new format. + */ + struct linux_dirent64 *de; + struct target_dirent *tde; + int len = ret; + int tlen = 0; + + de = dirp; + tde = (struct target_dirent *)dirp; + while (len > 0) { + int namelen, treclen; + int reclen = de->d_reclen; + uint64_t ino = de->d_ino; + int64_t off = de->d_off; + uint8_t type = de->d_type; + + namelen = strlen(de->d_name); + treclen = offsetof(struct target_dirent, d_name) + namelen + 2; + treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long)); + + memmove(tde->d_name, de->d_name, namelen + 1); + tde->d_ino = tswapal(ino); + tde->d_off = tswapal(off); + tde->d_reclen = tswap16(treclen); + /* + * The target_dirent type is in what was formerly a padding + * byte at the end of the structure: + */ + *(((char *)tde) + treclen - 1) = type; + + de = (struct linux_dirent64 *)((char *)de + reclen); + tde = (struct target_dirent *)((char *)tde + treclen); + len -= reclen; + tlen += treclen; + } + ret = tlen; + } + unlock_user(dirp, arg2, ret); +#endif + return ret; +} +#endif /* TARGET_NR_getdents */ + +#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) +static int do_getdents64(abi_long arg1, abi_long arg2, abi_long arg3) +{ + struct linux_dirent64 *dirp; + abi_long count = arg3; + int ret; + + dirp = lock_user(VERIFY_WRITE, arg2, count, 0); + if (!dirp) { + return -TARGET_EFAULT; + } + ret = get_errno(sys_getdents64(arg1, dirp, count)); + if (!is_error(ret)) { + struct linux_dirent64 *de; + int len = ret; + int reclen; + de = dirp; + while (len > 0) { + reclen = de->d_reclen; + if (reclen > len) { + break; + } + de->d_reclen = tswap16(reclen); + tswap64s((uint64_t *)&de->d_ino); + tswap64s((uint64_t *)&de->d_off); + de = (struct linux_dirent64 *)((char *)de + reclen); + len -= reclen; + } + } + unlock_user(dirp, arg2, ret); + return ret; +} +#endif /* TARGET_NR_getdents64 */ + #if defined(TARGET_NR_pivot_root) && defined(__NR_pivot_root) _syscall2(int, pivot_root, const char *, new_root, const char *, put_old) #endif @@ -10227,162 +10397,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, #endif #ifdef TARGET_NR_getdents case TARGET_NR_getdents: -#ifdef EMULATE_GETDENTS_WITH_GETDENTS -#if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 - { - struct target_dirent *target_dirp; - struct linux_dirent *dirp; - abi_long count = arg3; - - dirp = g_try_malloc(count); - if (!dirp) { - return -TARGET_ENOMEM; - } - - ret = get_errno(sys_getdents(arg1, dirp, count)); - if (!is_error(ret)) { - struct linux_dirent *de; - struct target_dirent *tde; - int len = ret; - int reclen, treclen; - int count1, tnamelen; - - count1 = 0; - de = dirp; - if (!(target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) - return -TARGET_EFAULT; - tde = target_dirp; - while (len > 0) { - reclen = de->d_reclen; - tnamelen = reclen - offsetof(struct linux_dirent, d_name); - assert(tnamelen >= 0); - treclen = tnamelen + offsetof(struct target_dirent, d_name); - assert(count1 + treclen <= count); - tde->d_reclen = tswap16(treclen); - tde->d_ino = tswapal(de->d_ino); - tde->d_off = tswapal(de->d_off); - memcpy(tde->d_name, de->d_name, tnamelen); - de = (struct linux_dirent *)((char *)de + reclen); - len -= reclen; - tde = (struct target_dirent *)((char *)tde + treclen); - count1 += treclen; - } - ret = count1; - unlock_user(target_dirp, arg2, ret); - } - g_free(dirp); - } -#else - { - struct linux_dirent *dirp; - abi_long count = arg3; - - if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) - return -TARGET_EFAULT; - ret = get_errno(sys_getdents(arg1, dirp, count)); - if (!is_error(ret)) { - struct linux_dirent *de; - int len = ret; - int reclen; - de = dirp; - while (len > 0) { - reclen = de->d_reclen; - if (reclen > len) - break; - de->d_reclen = tswap16(reclen); - tswapls(&de->d_ino); - tswapls(&de->d_off); - de = (struct linux_dirent *)((char *)de + reclen); - len -= reclen; - } - } - unlock_user(dirp, arg2, ret); - } -#endif -#else - /* Implement getdents in terms of getdents64 */ - { - struct linux_dirent64 *dirp; - abi_long count = arg3; - - dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!dirp) { - return -TARGET_EFAULT; - } - ret = get_errno(sys_getdents64(arg1, dirp, count)); - if (!is_error(ret)) { - /* Convert the dirent64 structs to target dirent. We do this - * in-place, since we can guarantee that a target_dirent is no - * larger than a dirent64; however this means we have to be - * careful to read everything before writing in the new format. - */ - struct linux_dirent64 *de; - struct target_dirent *tde; - int len = ret; - int tlen = 0; - - de = dirp; - tde = (struct target_dirent *)dirp; - while (len > 0) { - int namelen, treclen; - int reclen = de->d_reclen; - uint64_t ino = de->d_ino; - int64_t off = de->d_off; - uint8_t type = de->d_type; - - namelen = strlen(de->d_name); - treclen = offsetof(struct target_dirent, d_name) - + namelen + 2; - treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long)); - - memmove(tde->d_name, de->d_name, namelen + 1); - tde->d_ino = tswapal(ino); - tde->d_off = tswapal(off); - tde->d_reclen = tswap16(treclen); - /* The target_dirent type is in what was formerly a padding - * byte at the end of the structure: - */ - *(((char *)tde) + treclen - 1) = type; - - de = (struct linux_dirent64 *)((char *)de + reclen); - tde = (struct target_dirent *)((char *)tde + treclen); - len -= reclen; - tlen += treclen; - } - ret = tlen; - } - unlock_user(dirp, arg2, ret); - } -#endif - return ret; + return do_getdents(arg1, arg2, arg3); #endif /* TARGET_NR_getdents */ #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) case TARGET_NR_getdents64: - { - struct linux_dirent64 *dirp; - abi_long count = arg3; - if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) - return -TARGET_EFAULT; - ret = get_errno(sys_getdents64(arg1, dirp, count)); - if (!is_error(ret)) { - struct linux_dirent64 *de; - int len = ret; - int reclen; - de = dirp; - while (len > 0) { - reclen = de->d_reclen; - if (reclen > len) - break; - de->d_reclen = tswap16(reclen); - tswap64s((uint64_t *)&de->d_ino); - tswap64s((uint64_t *)&de->d_off); - de = (struct linux_dirent64 *)((char *)de + reclen); - len -= reclen; - } - } - unlock_user(dirp, arg2, ret); - } - return ret; + return do_getdents64(arg1, arg2, arg3); #endif /* TARGET_NR_getdents64 */ #if defined(TARGET_NR__newselect) case TARGET_NR__newselect: From patchwork Thu Nov 11 11:05:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 519123 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp115316imj; Thu, 11 Nov 2021 03:12:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJz8ByAOaq/O+FzRaX0P/lzMC0EaRWqzcZ5VxEkiFqFji1FUv9cRhddUCg2yclf4OJ9b/H6+ X-Received: by 2002:a67:d893:: with SMTP id f19mr9079575vsj.39.1636629127139; Thu, 11 Nov 2021 03:12:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636629127; cv=none; d=google.com; s=arc-20160816; b=b1YWsCfPMtPmVQPUe4Ijc+B3zv2tV/SRf4t8my387o5Rp//DGQ2lHr7s8La9zhQN4H yrwuTrzEEvryk/nVgQ8W4qitfwMtA7wFO2niewT7Wq+gUA9qTf11TEHXipVgRlJr2HZe 772nqi4qIrxaTIHxNZf2cMbuL3KmvxPlHOyKSqMeuke3fr6Ezt4QMaRlKo6qOSQsxiCZ h2Nb4fzNR94S6w2dnrLo8Qf8J0jXP5gxBSqT++v3XrmhsMe69MyIz0vxsBtPgUkWqOcn 35AcMEsGHITB9c4MomVqxSuBZ90iwjriQ3Z5HwuEugJ0GIn52jpkhgEjd1iYjww7zs8J VfVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=4Ue9aGUavsUkq+ShZeIUgd8duye3YsEvk3s9aGHMy6o=; b=iFFSkkivo5VYitcgnRqKPKSCCA4nkIgWQ7te/GPjwmFxnLRsKAeAFdj9160qLBfzGY dWZs6lm3coOKIdTz7o09fm+nWoBSpyt5xdw7LojLce7qhg1vTLV1cHwFwj0iLUSZrmAv A+9WFk9HyyejrqN5bIAo+jYO3pnIPFD3ZZxmUMLjdZ4Yf1PprQNUCRL3lEZ/BDIwFZjU vlxeIctKTCpdmgjMNGQ2SIRweOIiXj0ZoyRZfzGQB3ATVTeifF7TfmZqSgIaDvv8XOLr uguZ34OEjLH4L8O0yyPnKw4w5LAx3qqy2xJDa9b4mdjKNV7TP4SJRQeeTwx3IyXuzyEJ X2xA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t6si5802138uar.51.2021.11.11.03.12.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Nov 2021 03:12:07 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:38174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml7zy-0004PG-Jm for patch@linaro.org; Thu, 11 Nov 2021 06:12:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml7tW-0002b1-51 for qemu-devel@nongnu.org; Thu, 11 Nov 2021 06:05:26 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:34435) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml7tS-0001Nw-Df for qemu-devel@nongnu.org; Thu, 11 Nov 2021 06:05:25 -0500 Received: from quad ([82.142.28.210]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N7Qkv-1mdRKl3U6f-017pun; Thu, 11 Nov 2021 12:05:11 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 2/4] linux-user: Always use flexible arrays for dirent d_name Date: Thu, 11 Nov 2021 12:05:02 +0100 Message-Id: <20211111110504.1574242-3-laurent@vivier.eu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211111110504.1574242-1-laurent@vivier.eu> References: <20211111110504.1574242-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Y7N1/nm7yO02QgfWbhhUhL4aYf/7Q8jdUY37z1DheT+OjE5Y0al hKn9m1LmI+J2HmS5fayEO8bKblA/FfOvM4akdbTxKw9uwpVJB8X1u4QJT8sqf/2KjF4UXiw fE+h0s5QeaipsMZ+sd32DUfPGmn3gRLByV/HDxqKt+HLXI37DkOYMRgapgVLO+8NJ01pRQo 9C0B4oib7BTlHmZQF1SDw== X-UI-Out-Filterresults: notjunk:1;V03:K0:gVWWFhXmH2s=:oIEwGSh7Bu9h44Iag04vSA 3ZV4SFjkxBo8WhyCBY+jEM46UWIB8uLRJcrOI9xViYqRqfyQTENDETFnFDHjT73vFhQWN/tCM +fhUjIQsRgnwGK2uQU8c0cZbT3qxhCkNe9ddeaeRROxg7vOHBFGa+csnIWfrjlvjYqpzhr51O XvljRKLRvcIRg9LCVBuxhpejUqlcGMeeScySMwlei5uAU9ElcOuY7eLYldJTWXrwSsUkoqoLo 3pvcGTAqxU7AoUmILwN4p8n2516xoYNgTZT20IkKXvnZiWqFt0FrlB9boNqG57l5Dv8HPSPyN 9ZSBI1xVxN+WPxV2GL6rHe2H65RwjLx0CHWrmJ6mVQl6GB4htCUx83zeoZbIM1OvNuxwpAkEt NkEyVWKvgsIBz2mRaL8hzIuHm4G6/ZUtFIYxld+QhuubWZoiyQv2a1y09nDX/dDou9Jm+12sU M0D2+IlcSdj+ZDPPcpVkvihzj4OV4CA1HRRnte6TPHNtpJc8ScOLwaBUgnkhyj5MPxbFTXdyk kMEbq5fbPosWwYIoXL8hURRay3mmiVDxOBCapEff4ztlmaSoczy8m0lZkx8xN/x8xJMA0l4iT XCuFsRQAs8IYmTLBILTgDg/WVQAkEnq0cWaQSpLOyHwsI6IaJm2RRb/GaXXL1kciyobymAnG1 JNdgprHLqWil1opcPWNLCQtAhqhF/KU4A4Tlr6nNpXBjdzk5+0KIzaSrO2CXwNIH2Hw4= Received-SPF: none client-ip=212.227.126.131; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson We currently use a flexible array member for target_dirent, but use incorrectly fixed length arrays for target_dirent64, linux_dirent and linux_dirent64. This requires that we adjust the definition of the VFAT READDIR ioctls which hard-code the 256 namelen size into the ioctl constant. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed by: Warner Losh Message-Id: <20211107124845.1174791-3-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 6 ++++-- linux-user/syscall_defs.h | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index a2f605dec4ca..499415ad81b8 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -197,8 +197,10 @@ //#define DEBUG_ERESTARTSYS //#include -#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2]) -#define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2]) +#define VFAT_IOCTL_READDIR_BOTH \ + _IOC(_IOC_READ, 'r', 1, (sizeof(struct linux_dirent) + 256) * 2) +#define VFAT_IOCTL_READDIR_SHORT \ + _IOC(_IOC_READ, 'r', 2, (sizeof(struct linux_dirent) + 256) * 2) #undef _syscall0 #undef _syscall1 diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index a5ce487dcc38..98b09ee6d656 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -441,7 +441,7 @@ struct target_dirent64 { int64_t d_off; unsigned short d_reclen; unsigned char d_type; - char d_name[256]; + char d_name[]; }; @@ -2714,7 +2714,7 @@ struct linux_dirent { long d_ino; unsigned long d_off; unsigned short d_reclen; - char d_name[256]; /* We must not include limits.h! */ + char d_name[]; }; struct linux_dirent64 { @@ -2722,7 +2722,7 @@ struct linux_dirent64 { int64_t d_off; unsigned short d_reclen; unsigned char d_type; - char d_name[256]; + char d_name[]; }; struct target_mq_attr { From patchwork Thu Nov 11 11:05:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 519122 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp114933imj; Thu, 11 Nov 2021 03:11:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJxSg/B9FFRmC/CjskZG6OXd6XSPNKy9mt1+n4mzb4+xF9cb+n1QeKq48713Dedl1jcui0fI X-Received: by 2002:a05:6102:240b:: with SMTP id j11mr9433093vsi.54.1636629102071; Thu, 11 Nov 2021 03:11:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636629102; cv=none; d=google.com; s=arc-20160816; b=DjziuhdtVPRPitkRH+WW8yGrZMII37vnXw/Hz8jc3AAPjDdfZOPvCDRv7+Bs6iBVWp 8TUVs2ZD8oWVhPyYpudUeGN1epqDov0PvGGuFfSEPKqenl+occMlpFlBRwSkwxa59OBq nqxOzRWI5n6K3R/8E8/9RxL1kxLzbxdcQPDAifHkNOoSkAMKnUGo/uVr9yKQxzY2DO3P I6w7HAIw4733oEZcqgVbdyx1AKVhw+HfAcYe5wS7U3qQp9TEBzJfOWxKKpBPngYXnRHv mlYdwiUojVGcX+R1voTBTw3fXMARnOGp8JbOD49Dv4KI56Wj1xDgcJXqp3aQl8LCafqg jYHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=Lpb2baY8CYylug5/5CBTdDLaVS9xzhtoztEDCs00DQA=; b=GmGyQRMexP6KejY1SC5vCMcWG/gYeUrZTlFUFyrT17F2DQxVeGN1dvbJcjfHfPnFLI yaOMc+lw6RDJKPbveknn+wjW1os3QQ+D2IMqusFdXdMd4rVtT7U8kAeN/gB+e99Zqdmf hsgZSmU0Mkt2H3wk1Xir9wd4rnfPZmeeN1E3oOimgGVdgZ6ROeVbEtj/1nej2MtkxxY7 cKppu3zBQ+wjiHCYgzgZIrx4+6xpbYF0JkdBYlgotz2MFG9oEnsmU5IqN8f3DCrlmnKc B8CdqtyuJwJF8EuaCrSL7WzrFrZM09pOilVAgMzvpKIVjYn6sKg6O0MTjhUeuuc1KXOK V97Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c15si8188786uav.248.2021.11.11.03.11.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Nov 2021 03:11:42 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:36262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml7zZ-00035T-Hz for patch@linaro.org; Thu, 11 Nov 2021 06:11:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50898) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml7tW-0002b0-4T for qemu-devel@nongnu.org; Thu, 11 Nov 2021 06:05:26 -0500 Received: from mout.kundenserver.de ([212.227.126.130]:54135) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml7tS-0001Nv-CA for qemu-devel@nongnu.org; Thu, 11 Nov 2021 06:05:24 -0500 Received: from quad ([82.142.28.210]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N6KpF-1meXGQ3BvN-016jz7; Thu, 11 Nov 2021 12:05:12 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 3/4] linux-user: Fix member types of target_dirent64 Date: Thu, 11 Nov 2021 12:05:03 +0100 Message-Id: <20211111110504.1574242-4-laurent@vivier.eu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211111110504.1574242-1-laurent@vivier.eu> References: <20211111110504.1574242-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:MHeItdKQchzjaWl/nHXVTZ1lDL5JLxmJWrN0/boKiHLiRF3IlMW 1RrQkNr36SxM80tWAd9eb7COh55v8Cxq5jvgyMrpraTTV7eScFE38jVZrc+zgTl6LXqstN0 nhkzpu6gWLTnZZGat9XQcUYYR5E2OWwsEB5nI+F6ZSphrizr19AaD9L0eXLj9HmYdIwcX3D umukmdLdzKLfDtltmmtqQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:6mvheDXUhiA=:LnCvNZlzL/Wbjzs9M8VzNa oVbttN6uZKs0rz90bMBCJg0Et9+lEInNw2ub1xN1/pz2OASxDcS5DD7cpNqxF5GJWUK/IaCH6 mH16yhNSFA2viaou+x/u1RaDfkzqzi/lsRtx0heCSu6/8lF4ib0mVZfjAs/ZRMeTRr+cMZ1pQ K/azjHFxT0g67k0VDQx1YDj/Nj4+W8P4KoQ52RACpPrrh20bAKrHFTRCZ66z5WXJv0IYJpWql RqnF4m5L4XQLIiopOnii+/ALzEYD6KkPU9N19mufoiWs7XdFW76W/abZEd0wSj24EgV2MtVbu JPy0a83vKD3tcwuA/IbbsHv0Dg0T62AWYqlDSz3wwawf87Odhny08dNsz06KFl/m8JdSJYEck rB0NGaaEyyKeBJx2aJ3n5PAWPG8ngwYPVExQ3xmli5i/xDct3NdrXScr5r12iyQnYleMLNwrZ PAvJ2OnKtVf/W9qgZjNO7KWwVQm4xNQhdQkBENdXdYPx9WFO+IZLVTg7opoTH5XgGXEYHYprl 46YEtlTyvzAgm2J69+v+JORE5izZj90ZNWHcVr5MQRL5KlqONgQztxoTqyQCAp8kT+eDcThSW Ek3+Stnj4stUIIDq4OJ8/C4CMOoL3B/vEkLYZq+ehhIKnGoGUh9aCzT/nHof6AP0+meIrTY53 NUa0LWrHv4q5GMHAlbLEIgHmRQHuJmzgKc+48RYedrEc39DMqic0Yl8UQ2UTO885OO+Q= Received-SPF: none client-ip=212.227.126.130; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson The host uint64_t (etc) does not have the correct alignment constraint as the guest: use abi_* types. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed by: Warner Losh Message-Id: <20211107124845.1174791-4-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall_defs.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 98b09ee6d656..41aaafbac12c 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -437,9 +437,9 @@ struct target_dirent { }; struct target_dirent64 { - uint64_t d_ino; - int64_t d_off; - unsigned short d_reclen; + abi_ullong d_ino; + abi_llong d_off; + abi_ushort d_reclen; unsigned char d_type; char d_name[]; }; From patchwork Thu Nov 11 11:05:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 519118 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp109250imj; Thu, 11 Nov 2021 03:06:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFcgZxje8fJRe1QODfxomYCbQ7j4qE74yrKoduwSQ2Ge4m5oV4XOYHsdUdKKylRFtRmSud X-Received: by 2002:ab0:45a8:: with SMTP id u37mr9581220uau.24.1636628795027; Thu, 11 Nov 2021 03:06:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636628795; cv=none; d=google.com; s=arc-20160816; b=r23YDqCDUYpQxeAzUZ1K+R+VCsayX0jKDaeEsAbcwt/QsBipTQFa84kEEBYFcw+Pv4 xaLsSA00FclBfVCOiBufEvzkpbWhSdku+RNc2VhNhmVtDb+v20+sZy1WVnSY1auNNSLk OIG3MsXDjVqiezAC9Acnd439oneGYnq53L01QRIsKdnXkb3Ba2XZNQyzk18DICAwVKaM 26j8lTyvfX3mVZjkhxYiaLAKlnjdTB4UOkC7D7wJpKlRFK/jBh14JR0KfcBBPkpuels+ XRe32SjrwIUttrkdTqcN4pfoIXLRHo+pTv3p0O771CfX4GQXDuwow2AUCMkc8ab3yn3y TXPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=yOON36q1tYoVxoLasEiXWrg2DXGkYy/6SoReFP2QFP8=; b=Edpzmjmp0dj/bolobMclA8QTW/t6TSRlSDNxWqEsEHOLPcxFVt0XNbkH1fETuWmU3Q vX6YYqLszZb8Go/kXXG2eJrGbpTsCGmSE090p85NeFrCfvr6BIWuYb/BZA/ShiCK1tXK vVBSdxv7Y80ScSfG8IuMfkt5D4S05/OicG+NUIogRVfS6MI0jmGrdd1yOXWyqq3Y3Pb9 2l8061DyRhDbGQC+bYBs/JnjyULNZ01SuL/kFbigp2ozcW+VUY0ZUtJXIKPNqEDMlQVP 4VOPJ+vMJLtompYFFUKAWvRg5EMkV/80CtMcX+c+vfiiur/77CrDCftBUMxIC91T9fLC hb9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g22si5325503vsf.372.2021.11.11.03.06.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Nov 2021 03:06:35 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:51686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml7uc-0002WQ-Ef for patch@linaro.org; Thu, 11 Nov 2021 06:06:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50790) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml7tN-0002UE-KD for qemu-devel@nongnu.org; Thu, 11 Nov 2021 06:05:17 -0500 Received: from mout.kundenserver.de ([212.227.126.133]:47505) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml7tL-0001NC-Aw for qemu-devel@nongnu.org; Thu, 11 Nov 2021 06:05:17 -0500 Received: from quad ([82.142.28.210]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MwwuJ-1mWK4B2K6d-00ySVn; Thu, 11 Nov 2021 12:05:13 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 4/4] linux-user: Rewrite do_getdents, do_getdents64 Date: Thu, 11 Nov 2021 12:05:04 +0100 Message-Id: <20211111110504.1574242-5-laurent@vivier.eu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211111110504.1574242-1-laurent@vivier.eu> References: <20211111110504.1574242-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:TrBN8cvwb47goh6sHFTlUqiwrGspctKFmIUoUl1kuFEYWshXjzN PeSHNpUu1tjArmbbrxb7xcAQrWuhxcp5JR4vUmNw/r4xSqe9JreosX84Sf8MHbs20RKF+3W VrfO1rCiYMD0csxQVCgyyVugndDpDBHbS/CHe9Nr3Yzsznx2yfkLXUWEF+e0R9jCZQW84vs Idhe/OslXAz2z1aw6k5RA== X-UI-Out-Filterresults: notjunk:1;V03:K0:KSW34BrYp7U=:YYPwYIYcoD4oOXjaN3PA+u 7tFFKxRYqU8zDo5sWQXLWWL5iMY9AFRKxVTyDCCKPWQpShgoJfyoR5MLNspsA2td86UcrFovH lCV3IFer0EnfTJQzmfJMBRW1KHgA347e0VmciiI8S/dVm6qj51JhCba8AxNbI7DyFrAfg+SES hK7kOKr0DEM/z29zZhPP1Zssu53Veb2ozw8hHjzx/OcOoGnims1TMPXLsQOMnAE9grvdVRF38 FdFV1OMTn13YAk6aBn1qFwWqb3yrGgq8KVoGpr2P3rHqFUxpapfqgpZDip6TmLaafRNA1UpCU vpwdtnVusnpCh5VPJ7/ggTyZThCjnaGUrX4XL4oPVnavRg6VHMRKv9P4IhGOD5ov4tAnip1Gf 1HbTxWPSUA4O0X03rb//v+F6KeCglqEal6EPBBEE7CC1+7SmLvhSfI0vcZ4Qus3FdvE+t3SLr RIeCAfIoMYd2AKXto+MACtH2BVwr9HpGd+ymSkCUX8mfpuiDFFCOQ8IPauJuyiQ+I+y8DAC8/ OyLmtmvIRMFhUqH+ViNfHHk1cdplDxDOWRAndrEPUuNd9J7zi2+WhUjJ+lLvYLflyBweC7fcX Hl69xFf3ZV/MQoonJb0w8bjmTXcDhwrHf2hxtsyI4R5zDU9WQe88nGnsONoyIWMny4iWvYQU9 PS/6G73yoBDqPiOLydm+uRuNKrgz+2ivOja8bQhyQ+yEwBhe9tVhDPnhYkwchXUYnPjE= Received-SPF: none client-ip=212.227.126.133; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Always allocate host storage; this ensures that the struct is sufficiently aligned for the host. Merge the three host implementations of getdents via a few ifdefs. Utilize the same method for do_getdents64. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/704 Signed-off-by: Richard Henderson Message-Id: <20211107124845.1174791-5-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 243 ++++++++++++++++++------------------------- 1 file changed, 101 insertions(+), 142 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 499415ad81b8..01efd5773b9a 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8140,172 +8140,131 @@ static int host_to_target_cpu_mask(const unsigned long *host_mask, } #ifdef TARGET_NR_getdents -static int do_getdents(abi_long arg1, abi_long arg2, abi_long arg3) +static int do_getdents(abi_long arg1, abi_long arg2, abi_long count) { - int ret; + g_autofree void *hdirp = NULL; + void *tdirp; + int hlen, hoff, toff; + int hreclen, treclen; + + hdirp = g_try_malloc(count); + if (!hdirp) { + return -TARGET_ENOMEM; + } #ifdef EMULATE_GETDENTS_WITH_GETDENTS -# if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 - struct target_dirent *target_dirp; - struct linux_dirent *dirp; - abi_long count = arg3; + hlen = sys_getdents(arg1, hdirp, count); +#else + hlen = sys_getdents64(arg1, hdirp, count); +#endif - dirp = g_try_malloc(count); - if (!dirp) { - return -TARGET_ENOMEM; + hlen = get_errno(hlen); + if (is_error(hlen)) { + return hlen; } - ret = get_errno(sys_getdents(arg1, dirp, count)); - if (!is_error(ret)) { - struct linux_dirent *de; - struct target_dirent *tde; - int len = ret; - int reclen, treclen; - int count1, tnamelen; - - count1 = 0; - de = dirp; - target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!target_dirp) { - return -TARGET_EFAULT; - } - tde = target_dirp; - while (len > 0) { - reclen = de->d_reclen; - tnamelen = reclen - offsetof(struct linux_dirent, d_name); - assert(tnamelen >= 0); - treclen = tnamelen + offsetof(struct target_dirent, d_name); - assert(count1 + treclen <= count); - tde->d_reclen = tswap16(treclen); - tde->d_ino = tswapal(de->d_ino); - tde->d_off = tswapal(de->d_off); - memcpy(tde->d_name, de->d_name, tnamelen); - de = (struct linux_dirent *)((char *)de + reclen); - len -= reclen; - tde = (struct target_dirent *)((char *)tde + treclen); - count1 += treclen; - } - ret = count1; - unlock_user(target_dirp, arg2, ret); - } - g_free(dirp); -# else - struct linux_dirent *dirp; - abi_long count = arg3; - - dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!dirp) { + tdirp = lock_user(VERIFY_WRITE, arg2, count, 0); + if (!tdirp) { return -TARGET_EFAULT; } - ret = get_errno(sys_getdents(arg1, dirp, count)); - if (!is_error(ret)) { - struct linux_dirent *de; - int len = ret; - int reclen; - de = dirp; - while (len > 0) { - reclen = de->d_reclen; - if (reclen > len) { - break; - } - de->d_reclen = tswap16(reclen); - tswapls(&de->d_ino); - tswapls(&de->d_off); - de = (struct linux_dirent *)((char *)de + reclen); - len -= reclen; - } - } - unlock_user(dirp, arg2, ret); -# endif + + for (hoff = toff = 0; hoff < hlen; hoff += hreclen, toff += treclen) { +#ifdef EMULATE_GETDENTS_WITH_GETDENTS + struct linux_dirent *hde = hdirp + hoff; #else - /* Implement getdents in terms of getdents64 */ - struct linux_dirent64 *dirp; - abi_long count = arg3; + struct linux_dirent64 *hde = hdirp + hoff; +#endif + struct target_dirent *tde = tdirp + toff; + int namelen; + uint8_t type; - dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!dirp) { - return -TARGET_EFAULT; - } - ret = get_errno(sys_getdents64(arg1, dirp, count)); - if (!is_error(ret)) { /* - * Convert the dirent64 structs to target dirent. We do this - * in-place, since we can guarantee that a target_dirent is no - * larger than a dirent64; however this means we have to be - * careful to read everything before writing in the new format. + * If somehow the host dirent is smaller than the target dirent, + * then the host could return more dirent in the buffer than we + * can pass on to the host. This could be fixed by returning + * fewer dirent to the guest and lseek on the dirfd to reset the + * file pointer to the final hde->d_off. */ - struct linux_dirent64 *de; - struct target_dirent *tde; - int len = ret; - int tlen = 0; + QEMU_BUILD_BUG_ON(sizeof(*hde) < sizeof(*tde)); - de = dirp; - tde = (struct target_dirent *)dirp; - while (len > 0) { - int namelen, treclen; - int reclen = de->d_reclen; - uint64_t ino = de->d_ino; - int64_t off = de->d_off; - uint8_t type = de->d_type; - - namelen = strlen(de->d_name); - treclen = offsetof(struct target_dirent, d_name) + namelen + 2; - treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long)); - - memmove(tde->d_name, de->d_name, namelen + 1); - tde->d_ino = tswapal(ino); - tde->d_off = tswapal(off); - tde->d_reclen = tswap16(treclen); - /* - * The target_dirent type is in what was formerly a padding - * byte at the end of the structure: - */ - *(((char *)tde) + treclen - 1) = type; + namelen = strlen(hde->d_name); + hreclen = hde->d_reclen; + treclen = offsetof(struct target_dirent, d_name) + namelen + 2; + treclen = QEMU_ALIGN_UP(treclen, __alignof(struct target_dirent)); - de = (struct linux_dirent64 *)((char *)de + reclen); - tde = (struct target_dirent *)((char *)tde + treclen); - len -= reclen; - tlen += treclen; - } - ret = tlen; - } - unlock_user(dirp, arg2, ret); + tde->d_ino = tswapal(hde->d_ino); + tde->d_off = tswapal(hde->d_off); + tde->d_reclen = tswap16(treclen); + memcpy(tde->d_name, hde->d_name, namelen + 1); + + /* + * The getdents type is in what was formerly a padding byte at the + * end of the structure. + */ +#ifdef EMULATE_GETDENTS_WITH_GETDENTS + type = *((uint8_t *)hde + hreclen - 1); +#else + type = hde->d_type; #endif - return ret; + *((uint8_t *)tde + treclen - 1) = type; + } + + unlock_user(tdirp, arg2, toff); + return toff; } #endif /* TARGET_NR_getdents */ #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) -static int do_getdents64(abi_long arg1, abi_long arg2, abi_long arg3) +static int do_getdents64(abi_long arg1, abi_long arg2, abi_long count) { - struct linux_dirent64 *dirp; - abi_long count = arg3; - int ret; + g_autofree void *hdirp = NULL; + void *tdirp; + int hlen, hoff, toff; + int hreclen, treclen; + + hdirp = g_try_malloc(count); + if (!hdirp) { + return -TARGET_ENOMEM; + } + + hlen = get_errno(sys_getdents64(arg1, hdirp, count)); + if (is_error(hlen)) { + return hlen; + } - dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!dirp) { + tdirp = lock_user(VERIFY_WRITE, arg2, count, 0); + if (!tdirp) { return -TARGET_EFAULT; } - ret = get_errno(sys_getdents64(arg1, dirp, count)); - if (!is_error(ret)) { - struct linux_dirent64 *de; - int len = ret; - int reclen; - de = dirp; - while (len > 0) { - reclen = de->d_reclen; - if (reclen > len) { - break; - } - de->d_reclen = tswap16(reclen); - tswap64s((uint64_t *)&de->d_ino); - tswap64s((uint64_t *)&de->d_off); - de = (struct linux_dirent64 *)((char *)de + reclen); - len -= reclen; - } + + for (hoff = toff = 0; hoff < hlen; hoff += hreclen, toff += treclen) { + struct linux_dirent64 *hde = hdirp + hoff; + struct target_dirent64 *tde = tdirp + toff; + int namelen; + + /* + * If somehow the host dirent is smaller than the target dirent, + * then the host could return more dirent in the buffer than we + * can pass on to the host. This could be fixed by returning + * fewer dirent to the guest and lseek on the dirfd to reset the + * file pointer to the final hde->d_off. + */ + QEMU_BUILD_BUG_ON(sizeof(*hde) < sizeof(*tde)); + + namelen = strlen(hde->d_name) + 1; + hreclen = hde->d_reclen; + treclen = offsetof(struct target_dirent64, d_name) + namelen; + treclen = QEMU_ALIGN_UP(treclen, __alignof(struct target_dirent64)); + + tde->d_ino = tswap64(hde->d_ino); + tde->d_off = tswap64(hde->d_off); + tde->d_reclen = tswap16(treclen); + tde->d_type = hde->d_type; + memcpy(tde->d_name, hde->d_name, namelen); } - unlock_user(dirp, arg2, ret); - return ret; + + unlock_user(tdirp, arg2, toff); + return toff; } #endif /* TARGET_NR_getdents64 */