From patchwork Sun Nov 7 12:48:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516841 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp2303327iml; Sun, 7 Nov 2021 04:51:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzldXm76zLXBdwwzVfvk2tZFbWjj3Wi57NFCVcM6m9QDP9PJKCRpPkq1YlqGza3V8tSiW9t X-Received: by 2002:a05:6830:91a:: with SMTP id v26mr39567973ott.313.1636289495568; Sun, 07 Nov 2021 04:51:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636289495; cv=none; d=google.com; s=arc-20160816; b=wI6FaaVluFPglJcI/uBO4/+RFS5u3s9tF7711DbxHE8+35w+aNRvy1RXBh3t4IIL0R cKDeB0oLXpIo8AYm052M5PQIwpHYiW75fgq5L+5eWpxe65L7qaeEJPCiTFxU5naBanz/ 4gAkQO9qu4Uae7hi6fYqBpwEMGoiwa/a2fCSh66d1fvmN4nypKd8cwVyL3CH34gDqFhd Ep6Iymo6grmk1DQiZvozSbpNcHbtwxrmRHV6FV0WCVzENHLkZDH4/H9ObtxodjMAcsOp ntJVh6BFsQSRJ01Kyd5xSWYJbAnyNi8bSU/e4RRPlvpBNXOOyM9+8tnEQZN/wLeiMXiw zsWg== 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 :dkim-signature; bh=5YdY/iarwR1o7rlm4TvNfomS0+BmE8A5jrB21UT6FG8=; b=nBMGU7TTSvQRTQgJk6UKarORH0Pb6K3WHIyKW5c4nBIlFgprNelpskmJQiBf6kE5zv UhGC6c8CKf2ai8RrPwoeze44hUsU/avXJNZ6DTe6x33hkuieEc8XQ02Y746rjPA5yq58 ayDG5J/Yct2vEW9KijrGQRtqqKeBZ1bT8e9GaICtX1fslBDkKa8e+lNqLJ+pME1vnWcQ H9FL+Q2Aiv0YvA++01Bd/eyW0dTrGZN87eLIjlTb75WKvwjey9nLHZgG/Q5Wmuu4w2DB 5+XP+rzV4FM/L7b4JQL8l13ADEC3zmvwWynsCvKRVBYk4DiiEFVkgbOZZb3fmFx1Fnj1 E0aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RfJ8ccCy; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v2si2185437otn.7.2021.11.07.04.51.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Nov 2021 04:51: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; dkim=pass header.i=@linaro.org header.s=google header.b=RfJ8ccCy; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjhe2-0006QE-Tf for patch@linaro.org; Sun, 07 Nov 2021 07:51:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjhbO-00033w-QF for qemu-devel@nongnu.org; Sun, 07 Nov 2021 07:48:50 -0500 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]:33360) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjhbL-000269-MJ for qemu-devel@nongnu.org; Sun, 07 Nov 2021 07:48:50 -0500 Received: by mail-qk1-x735.google.com with SMTP id p17so12033661qkj.0 for ; Sun, 07 Nov 2021 04:48:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5YdY/iarwR1o7rlm4TvNfomS0+BmE8A5jrB21UT6FG8=; b=RfJ8ccCyNmw8lJnH0EywAbBWxThMm6HvmuJu+oiPEoYw09piV3cE3AC6X8oRHbe9WC CvJqK2GVW0uxgJSj1j5k5tLiIsigrX9ygFbPhN2qZBSdVlLIZPu1SaatRzTZUy9dHVHg u1NY86+Ptm8/05oGvqPwFFL/I/0hIUkS6KaRYwl9NmbeLFEECjytIsC1Qg1q5mt0E7Ia 0bACijXSGRg9XQoqP9TPer5oADkqy4Zv10pLc+Scq1H0bhp6CwftYxlBs3K0wdutit78 Bj6C8XdZQ1FO+pB/W7g0NVqP8nSifw6lCKIFi42/M5KkVFGxOqBxQN53DjepvU7OPkyb v58w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5YdY/iarwR1o7rlm4TvNfomS0+BmE8A5jrB21UT6FG8=; b=LtXHnpBZtUy9Yk7ckkar7H8gHodJl4eUCd8MaxiPma3GhAzwWm5jqBG8lkkMqFlP6U YkIMyIZP5f64Q5k6tbaougpzllpsz5I9JTe6KjqQZeRWTfWpxiwAEidhS+QheR8njfYN D9y2nXdPwGKFrV2kXInObqCGM+6nwaqhtYhw950LAP3j1UCi850HDfyS82OTPQXoqDsj ZxRNWuKup6v71oF8Kg/C77QvW3OvyixFK4oOf0Smyn6Mz8UUGy/ytwmUFFWeDAMMK0jV w/7ofPh6rcAyuqoXkZqN0PGgJ81JY1eGgimRgel7k0TbkCm4kX7goVAT+FaddbJxmzwo 0tmQ== X-Gm-Message-State: AOAM530Vug2cMPPVRvc5m8QdahfPhuZtd82RAE6eSrK2AeJTTFcQBryz WSp3X2tNvx/A2MTpKJa9dl/sPscHpuJZYg== X-Received: by 2002:a05:620a:b4c:: with SMTP id x12mr50762665qkg.324.1636289326717; Sun, 07 Nov 2021 04:48:46 -0800 (PST) Received: from localhost.localdomain ([38.66.81.217]) by smtp.gmail.com with ESMTPSA id w19sm6917qkw.49.2021.11.07.04.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 04:48:46 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 1/4] linux-user: Split out do_getdents, do_getdents64 Date: Sun, 7 Nov 2021 07:48:42 -0500 Message-Id: <20211107124845.1174791-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211107124845.1174791-1-richard.henderson@linaro.org> References: <20211107124845.1174791-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::735; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x735.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Retain all 3 implementations of getdents for now. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- 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 544f5b662f..a2f605dec4 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 Sun Nov 7 12:48:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516842 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp2303416iml; Sun, 7 Nov 2021 04:51:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJxfZjMJd+2Dg5EEG+ifu2eQLePw2asf/SkT51G2bAm5YJnFkHQs13SD8zgu1uSyEYNnnBB1 X-Received: by 2002:a05:6808:d46:: with SMTP id w6mr32502754oik.40.1636289502286; Sun, 07 Nov 2021 04:51:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636289502; cv=none; d=google.com; s=arc-20160816; b=vsnjITmyDJrlzgAgd/Uj+3baA0xcQoP0zqzgBQTY95+r4G5LrNaFX56CjXwJKbU5W4 n9AZKwa5c0AAkK0XsbRqxLjzmSdWjHsFvx2aPUj78XScq6+RgKs+0ECjc82xc5E5tsjA O52xGZsWBMVr+Foj3uv8cWSqQWzkiIRILzlOphTtvbjbehOrY+e9yxQmK5vgj5+V8PCG myasYP3RIUZco4/npAPh0vxb4xdZcl4Y0tpfKPxe6AvXdBCBdqmMgnG028MiOs+3sEE+ gdYpif0EccNGKzp7pzQ3TtMXmEKjdI8houNm3DhSEXyyAYZkJIIrr0k51ZZ1oE99YYZ8 0AEw== 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 :dkim-signature; bh=NgWRpb6eD25eDJnCmvoWcYOQSpkeHkzdEszyRb0jyTc=; b=mUYk4PEL+xMp343pjSa1IoYPWTxb6PTRKnXnvlN5LX8BwfRIXZAOI07ycsxkW9VP7j NxKCLKnKCB64fnqxhZn9IDKOOpg9aVwL4z605OlR4iZL1WKA8369nQl2ylDUOfja3pTo 8EBEK3kPTEGlFX7HC8Fx/ffcMRUTuOqsAcrznAJ7xONvEhKtWVC4uJ3Y22iBfuSN192+ 9qXBwQ9b7gkPoJ79uommb8Txx4svNqFt1d9TB4UGzCleJrZq52WhtjLVyeyBeTcsMA9u x3xETw2fTUQvfNXgchNF8HXqxcdzJDHvNy+9o1SujI1i5gBesCW9AI+daIDuedHgBESz +ZXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LHECL2Ax; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a1si18454687oiw.56.2021.11.07.04.51.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Nov 2021 04:51: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; dkim=pass header.i=@linaro.org header.s=google header.b=LHECL2Ax; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjhe9-0006X9-MW for patch@linaro.org; Sun, 07 Nov 2021 07:51:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjhbP-000343-9P for qemu-devel@nongnu.org; Sun, 07 Nov 2021 07:48:52 -0500 Received: from mail-qt1-x829.google.com ([2607:f8b0:4864:20::829]:38519) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjhbN-00026G-Ax for qemu-devel@nongnu.org; Sun, 07 Nov 2021 07:48:50 -0500 Received: by mail-qt1-x829.google.com with SMTP id c12so6803358qtd.5 for ; Sun, 07 Nov 2021 04:48:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NgWRpb6eD25eDJnCmvoWcYOQSpkeHkzdEszyRb0jyTc=; b=LHECL2AxH4ua7CW9c++czvjfYDapl6y+B5lIuI8XiO6N1nTsUJcbZphl9Mrak7QoY6 OrP2iMAhiT3Od+UfrUyOx+wR4dM2JxkaxCzPktxdEGUqaoP1R4Ld5/Mw1D+1lleCVbnQ ld+xQ07OYAvanqgFE/0i85tY8dwy5Tgdfztv30ZcfGYIvYphrNmw3OYH/XwiL5V2UIqN 4lTilUqnl/Q4nH9wtikfTsChP2TjoizrKWiStWtIwO3Op3koPeTAs6DFetB9Bl7MH6OB mq65Vw+YW5rtrsJb8R/tsuktpm0/1yaWMY8KlccFY+NxVKzf0Gxb95lcsmPOUi94QD3N HwDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NgWRpb6eD25eDJnCmvoWcYOQSpkeHkzdEszyRb0jyTc=; b=0B1vJnV5ZvgUh04S4C3CTYjc/eokM4y0TfLE/FWCvwrkEb63YP9l2awFQ9lvjqYYP+ PCmJc7lR//jszA+3rJBFegZXnzQH9ptoSFQC4QKwnn6PHPr36SaMc0WabLamluCKz+1Y uFdFdvZaVGg63FAP3vvW/IytnaSoown0J0CEG1/RcXi5VRQ3rKHA2lgAK74JolXd5sXw BPsgArChwm6z2I4ujymi+dPBqhpYQoORZiO3aF7lB4XQbMaRVypSf2j8lQAkv5LjL2Ta kGadTAC29DIMOGKGi6xU4QI+XAPPmPuhkBd/XN9xNDNmUIdZHcP2lsMawfCxk9NO3U9v VwaQ== X-Gm-Message-State: AOAM530mInmMP9+sReFg9OLFDfDBnPzE1ODOyqd7mcQT1Hv0WX+a0Vg8 WJq2X6qR9Wm06b8265rlMen7BwUZFxAkAQ== X-Received: by 2002:a05:622a:1449:: with SMTP id v9mr56241399qtx.122.1636289327300; Sun, 07 Nov 2021 04:48:47 -0800 (PST) Received: from localhost.localdomain ([38.66.81.217]) by smtp.gmail.com with ESMTPSA id w19sm6917qkw.49.2021.11.07.04.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 04:48:47 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 2/4] linux-user: Always use flexible arrays for dirent d_name Date: Sun, 7 Nov 2021 07:48:43 -0500 Message-Id: <20211107124845.1174791-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211107124845.1174791-1-richard.henderson@linaro.org> References: <20211107124845.1174791-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::829; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x829.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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é --- linux-user/syscall_defs.h | 6 +++--- linux-user/syscall.c | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index a5ce487dcc..98b09ee6d6 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 { diff --git a/linux-user/syscall.c b/linux-user/syscall.c index a2f605dec4..499415ad81 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 From patchwork Sun Nov 7 12:48:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516843 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp2304425iml; Sun, 7 Nov 2021 04:53:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOKWshyd8oYL5PkefYT5QyFJ4xWsx+nuOG58g7wML4lX071vj1+g9rhqQzPz47va77COa+ X-Received: by 2002:a67:a60b:: with SMTP id p11mr93512474vse.34.1636289585709; Sun, 07 Nov 2021 04:53:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636289585; cv=none; d=google.com; s=arc-20160816; b=raF3BagyQAeWOzxkHX7BGk8oslpln4gE21PMf6n0zTc0G2dY8cu+4Unhr0tIvgY3jZ Eo0Ku57hWPIGcSOivL7Kwk8UJfMuX8I81ES1woPwrnHwJ2gXvA66VSzOcDYT/uhx9lFw KW0AdCUzn0hLCqJ7YTsnyl0WDCKDeYOkXhRp5qfdsMiFBO0gg895aOWZvNMgKRoxC/qN MGOCviWoqBZyR2HUfkzHgvd77rkOv7YdlaMZrJ0Xkk9vVec0IEM4Win/KoF4lxkJAK5f tvFKc/nd5a3UHQTp352fCWik4NoT7yISKeWovQQL/7VnpPuWLT1vgVV2hXe/v2KAYSEv uv1Q== 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 :dkim-signature; bh=eGSHLpNAu9g6Np9tb4uVWnbjp2oiYs6nIhg97qpdgNI=; b=PQcXk312TipPsCtUrkO5+uzTwGMkwzWTEvqjjOd6lxkFOpUE36deTY91DvKKnZmWGH 1rQg+I+n0Ol7h5IiItdNXe7isntvwnUnY5hEkHyD7E/bmVgvmzG6J+W81MWK+zNYTa+r /pWpFkUMTuCMuS4MytJa5DFJm9YO46WsEwWbz4OvKR43ArbhCJsYKy6Z3WergkQH/QtX Cebe/L6D1fu93Ll0/Nxt976PUZuoSHVWkTDeEuP+pk4o/Mnq98/yfBUrqpC3MltwJMnE ISFuaLaNvXl8EGHhVbG4LPRyswGtJNwxoZ13K/lgIEuO7Lv4hXngjzBnuil5g0LcYkTJ WUYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oqyb73dj; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ay35si33048731uab.216.2021.11.07.04.53.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Nov 2021 04:53:05 -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; dkim=pass header.i=@linaro.org header.s=google header.b=oqyb73dj; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjhfV-0001Ih-6V for patch@linaro.org; Sun, 07 Nov 2021 07:53:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjhbO-00033x-Qc for qemu-devel@nongnu.org; Sun, 07 Nov 2021 07:48:50 -0500 Received: from mail-qt1-x82a.google.com ([2607:f8b0:4864:20::82a]:42817) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjhbM-00026I-Ru for qemu-devel@nongnu.org; Sun, 07 Nov 2021 07:48:50 -0500 Received: by mail-qt1-x82a.google.com with SMTP id h17so9113622qtx.9 for ; Sun, 07 Nov 2021 04:48:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eGSHLpNAu9g6Np9tb4uVWnbjp2oiYs6nIhg97qpdgNI=; b=oqyb73dj9QP7WWMkTJy6D5uMXQo+bkqh2hU0NeyaMQ15+S3FzK6Jz30OJjcpaLZ/6V i+n3erSM1cN2JuCHCHY1fkos5p8vRSKSl1uIwXopMktvya9QJaVMBKu2yxrhYeXxa7K1 X6uoXDzmJ4L92Fp1Pcd0YcY5cRTe3ES+dOt2f6mPCBWa40jcnc+rcAl/ZXDYsGzjweRF jm8PyiNJLmF8aqF4MNdtIdaDdnq6pnONZDPzd5tJ6w/9GVsqovtuw9B87HqDdrXx5g0E 6LsUGIbRWc9sB8diAqMki3G0qpN9gEfPR7dqNyByerBHXSpZSxqd7cMhA9mqk3nubOMp Tubg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eGSHLpNAu9g6Np9tb4uVWnbjp2oiYs6nIhg97qpdgNI=; b=Q0ELmwnXPcFpqQJl5j2LqubOsMbBUZ2VlhaUAMd5v7UdhTGDy6JcdyTfAiUzafjQTE 8NsrNwaoaefJ+pMc+uUExrg2DK/7MSv71KIfVVSXDL0f6ps5jSCTcEIEE298ve72O6KL LBK7APTknUD+JYD7bI1CGPfPcsjCaJKtrRdY2r8DqImWUAiUEOLqBW6H3tpUvaYNvz69 urB6/s2gQqI5GifiJCBwh5GULfGHL9bRVZAcMOtt2GVJGrzIMebUQI7YMjJ19PMuva28 9vGegDe6aXmGZejt+/LBTQGfRhpsaCd8CPs4mUIZxDRFjYEjXvjG4i+F04mMWZqNjQrV 02fA== X-Gm-Message-State: AOAM5335VLc6x64LRr0lIMCOOjf2N5wjnmzXOjgPS3Yjn8HszojL0CYq 7EDZ6iK4QWHR/rErwU3FdfYE+DMN79iMng== X-Received: by 2002:ac8:4547:: with SMTP id z7mr38555940qtn.50.1636289328016; Sun, 07 Nov 2021 04:48:48 -0800 (PST) Received: from localhost.localdomain ([38.66.81.217]) by smtp.gmail.com with ESMTPSA id w19sm6917qkw.49.2021.11.07.04.48.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 04:48:47 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 3/4] linux-user: Fix member types of target_dirent64 Date: Sun, 7 Nov 2021 07:48:44 -0500 Message-Id: <20211107124845.1174791-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211107124845.1174791-1-richard.henderson@linaro.org> References: <20211107124845.1174791-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::82a; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x82a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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é --- 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 98b09ee6d6..41aaafbac1 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 Sun Nov 7 12:48:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516840 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp2302119iml; Sun, 7 Nov 2021 04:50:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxKntZLCz3lkV1g3hRQ+vqEP6u/5Jjngh/b3EFh1XvbB5MUNfOO0mx1lP4TsZNVl/1KIRd X-Received: by 2002:a4a:b34a:: with SMTP id n10mr17366360ooo.46.1636289413687; Sun, 07 Nov 2021 04:50:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636289413; cv=none; d=google.com; s=arc-20160816; b=Cy+BKGfiEAEcivATts51qoHgMZDg4lD7L62/hi8EVPm60j1EnY2WGNjOUZ4lkm8Fhy Gt8LA/jOQWD2g4wPg4NaYPoij5WnbgqOfVnyDngpxFtYScaU+ZfbJC6QOLFBJvUo3W2m 9xZrpNPN//IBrpboOMDozhZ7uqOrPwv/rhF+52VbnFhotUk45feIv+q9eKTRxrGnqLFY ikhqBHxsJEJMqDEeC1C4oA7rNz3DsGqdSD4p4bOKsW5qeFaSQY6vUvYGS50Ovve5UmeF Njm2aI8ex8KtTA6yPESAYc5ewP/IwETcvqg4an2rAp1bsi1+w3Nk6sWzJkY4H8SJuXs9 DRTw== 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 :dkim-signature; bh=lAg3JSFvjX0uMfpuVPcBgi6f8K/h/oAtcH5TT2VrIrU=; b=lz8tZprtlP+HUCzaURyRQ2W+881ds8Rsag92CkltHBmsNQYZRHzLngg+YwcztFQy1k 2XykQnz9tIB0/bOvRyFopj79cNxeh0fBPUaIq2pinZof9fRiX8Ik6jPhrrJ8Wn6///+3 jfC2h0/RMIKK59YAh4ytG7g9MdDAKy2jDatNxhLQzUw3WZ2kLypt/zBUs6r1SgQQX2Op +7jmm8s//Jozmx/NYEeDKM3Olx5vTnh5foD8l5NRC0T9I9uQEcNVChCLy93TCzlHd7jV U/EWlw4smFhgQZCHjX/eLzuqfsavLy3bfox15M362j5sXcam51wp9ue7352h0RP30uGL dqaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R6GTb44w; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r24si5813597ooq.52.2021.11.07.04.50.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Nov 2021 04:50:13 -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; dkim=pass header.i=@linaro.org header.s=google header.b=R6GTb44w; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjhcj-00036o-2O for patch@linaro.org; Sun, 07 Nov 2021 07:50:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjhbQ-000347-Jq for qemu-devel@nongnu.org; Sun, 07 Nov 2021 07:48:53 -0500 Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]:43957) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjhbN-00026X-Gq for qemu-devel@nongnu.org; Sun, 07 Nov 2021 07:48:52 -0500 Received: by mail-qv1-xf30.google.com with SMTP id j9so10249976qvm.10 for ; Sun, 07 Nov 2021 04:48:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lAg3JSFvjX0uMfpuVPcBgi6f8K/h/oAtcH5TT2VrIrU=; b=R6GTb44wDyRiODByJbIFpoSS8/ko/9PV/EUI6VGRSnkvWVk2TlKgzyZcO9FOkKHBEk Hi+t0FGeCrBhGvc43vkjU8n1/G8AB+CaL1XABHNTTqZx48HtUrk3tRy2v0y/UF7qzeG+ s11gP8QelrY88JwZbaOXA37KXkHZeT6hUV1TprVegmSpB7g8gJUvjg60nZOOe8zY1oFz aknjPvUAFZsfidJgQJ2BOEvdvNwPMKuCfQu8LYV3ZjiKaDCAZQlQ7KlLcO8wmN4P646K 9HWQeXMwsE7PLXldvgJKNSTZIG7nd9s7d0YHBk0gusctLWBluM2qahEfzW7SBUypXmuz MZuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lAg3JSFvjX0uMfpuVPcBgi6f8K/h/oAtcH5TT2VrIrU=; b=yG0RxnCCUuUmDO+nAxeVYZMIHSTjV94zzUGpT/GgpzAT8Q/4EQT4d8ByUy0K1I1e2x Y8/tDGCQpqeddiw9J9wbNCe5gbw7F1tcmqifBwX094SO/waoiZTFeKI5lNSLmPSLVDja /O7RncVovySjf0JIYp3XE+J3ZkAz9Ls8tXm350Adcpj3w6W+szNtLvwZwhqHVQ/TkWDG aaK6F2I2C91GfTKak8I7W/3n4p+jm/Ljt+EjUhWYLhsidAdMVtw59TUGbAvnSFIAfPBR JPhzCSbGuj8NS6Y0q6XN8zBj0ZUTLZ7Fe0a/pMSmNRFx/3cSyhPFNbaLi4zp/Jijsqin A6HA== X-Gm-Message-State: AOAM5312Rd+axNDNCkNztR+MOCGsKZXMRDfjF7OicnT4r1vxUytvVhwV PCC10kx2//65HqSvu2nU1rn1MF9vFdtnAA== X-Received: by 2002:a05:6214:2307:: with SMTP id gc7mr11435100qvb.34.1636289328658; Sun, 07 Nov 2021 04:48:48 -0800 (PST) Received: from localhost.localdomain ([38.66.81.217]) by smtp.gmail.com with ESMTPSA id w19sm6917qkw.49.2021.11.07.04.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 04:48:48 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 4/4] linux-user: Rewrite do_getdents, do_getdents64 Date: Sun, 7 Nov 2021 07:48:45 -0500 Message-Id: <20211107124845.1174791-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211107124845.1174791-1-richard.henderson@linaro.org> References: <20211107124845.1174791-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f30; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf30.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- linux-user/syscall.c | 251 ++++++++++++++++++------------------------- 1 file changed, 105 insertions(+), 146 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 499415ad81..01efd5773b 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; -#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) { + hdirp = g_try_malloc(count); + if (!hdirp) { 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 +#ifdef EMULATE_GETDENTS_WITH_GETDENTS + hlen = sys_getdents(arg1, hdirp, count); #else - /* Implement getdents in terms of getdents64 */ - struct linux_dirent64 *dirp; - abi_long count = arg3; + hlen = sys_getdents64(arg1, hdirp, count); +#endif - dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!dirp) { + hlen = get_errno(hlen); + if (is_error(hlen)) { + return hlen; + } + + 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)) { - /* - * 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); + for (hoff = toff = 0; hoff < hlen; hoff += hreclen, toff += treclen) { +#ifdef EMULATE_GETDENTS_WITH_GETDENTS + struct linux_dirent *hde = hdirp + hoff; +#else + struct linux_dirent64 *hde = hdirp + hoff; #endif - return ret; + struct target_dirent *tde = tdirp + toff; + int namelen; + uint8_t type; + + /* + * 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); + hreclen = hde->d_reclen; + treclen = offsetof(struct target_dirent, d_name) + namelen + 2; + treclen = QEMU_ALIGN_UP(treclen, __alignof(struct target_dirent)); + + 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 + *((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; - dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!dirp) { + hdirp = g_try_malloc(count); + if (!hdirp) { + return -TARGET_ENOMEM; + } + + hlen = get_errno(sys_getdents64(arg1, hdirp, count)); + if (is_error(hlen)) { + return hlen; + } + + 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 */