Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp981747pxb; Tue, 3 Nov 2020 18:54:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5r5hN5Ut1R/h0IliyzFfnpZpdXnuW0UrSjibCA9GA/z+yIhIOOcD2hutbEXtLMvIoESUz X-Received: by 2002:aa7:dcd6:: with SMTP id w22mr9115775edu.19.1604458477146; Tue, 03 Nov 2020 18:54:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604458477; cv=none; d=google.com; s=arc-20160816; b=XnffjtdeEGyVJ0y0Gs6M4e6jLQh+uawlKBBvQeVj7+n41ky0MmZMpLjqJrPINUCZrO U1DbrKVIbNT4FwQKMRMFrn7K4wlXnr5NwcW3rlic+UVlzZsUxKRMpiUbq/Ww6qLySlcV iG7dHo7Q2ciN5vq/K472OQ7u9xs/xUt3+rqFD4oeC2AIs5AzRyWbaKLrjWQUvhkuAtE5 xPZu2dbjjS1GXAxDwO5vQI3dr6YaL/LyyBWltcWyfTZpK6H+8LMFhITMAKPujoU4L90+ LZ66AdueHu4Ve/ZSxjZz6Nd5hTdnocsWMZ5eLiX2odFoXic9RmsdejR5Crl2iuUZz8Zt LSDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=PjperagnsSXNR1M/Vl5WUpraD/wLfKttsQ/NFXSQ5ms=; b=hRvHbg7LzI8HhQDZ2vaEPIOGd4/12MG2O8hoaAn2KiurS1+0ijRrIsROpQJpkYKKsS 3Q/NOmH7Tiqld7Udrww6bdE7FDxXgfK1dESPRvITr2CDecDK3Ob5CaVUt7157WO7yPvr 0Fg65q4+hWgvfpBD1m7FHmsruRdGSgMSavfhhgQ1GGtgWxe+TnXculftRYbIA3vdOmYB QM0/RvRqj2PCW6kUnL2RHg1seJzQ/UYoml7AuJ3Kvz8jt/0Bw1UKUALen3a6FxZwIScz cCIAtlfFpYS7228EAG39h5FA8QCRyMPxhC2UdBMzcYFo1hui5eyJV92uPP7fOuI2/nBd szhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n4si535353ejk.692.2020.11.03.18.54.13; Tue, 03 Nov 2020 18:54:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729480AbgKDCwT (ORCPT + 99 others); Tue, 3 Nov 2020 21:52:19 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:7045 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729085AbgKDCwS (ORCPT ); Tue, 3 Nov 2020 21:52:18 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CQrlx4zPzzhZlN; Wed, 4 Nov 2020 10:52:13 +0800 (CST) Received: from [10.136.114.67] (10.136.114.67) by smtp.huawei.com (10.3.19.204) with Microsoft SMTP Server (TLS) id 14.3.487.0; Wed, 4 Nov 2020 10:52:14 +0800 Subject: Re: [f2fs-dev] [PATCH RFC] f2fs: fix compat F2FS_IOC_{MOVE, GARBAGE_COLLECT}_RANGE To: Eric Biggers CC: , , References: <20201104021906.108534-1-yuchao0@huawei.com> <20201104022908.GA832@sol.localdomain> From: Chao Yu Message-ID: <2d1f5f85-f1a1-edf1-82a4-ee47fd46c349@huawei.com> Date: Wed, 4 Nov 2020 10:52:13 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20201104022908.GA832@sol.localdomain> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.136.114.67] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/11/4 10:29, Eric Biggers wrote: > On Wed, Nov 04, 2020 at 10:19:06AM +0800, Chao Yu wrote: >> Eric reported a ioctl bug in below link: >> >> https://lore.kernel.org/linux-f2fs-devel/20201103032234.GB2875@sol.localdomain/ >> >> That said, on some 32-bit architectures, u64 has only 32-bit alignment, >> notably i386 and x86_32, so that size of struct f2fs_gc_range compiled >> in x86_32 is 20 bytes, however the size in x86_64 is 24 bytes, binary >> compiled in x86_32 can not call F2FS_IOC_GARBAGE_COLLECT_RANGE successfully >> due to mismatched value of ioctl command in betweeen binary and f2fs >> module, similarly, F2FS_IOC_MOVE_RANGE will fail too. >> >> In this patch we introduce two ioctls for compatibility of above special >> 32-bit binary: >> - F2FS_IOC32_GARBAGE_COLLECT_RANGE >> - F2FS_IOC32_MOVE_RANGE >> >> Signed-off-by: Chao Yu >> --- >> >> Jaegeuk, Eric, >> >> I have no 32-bit machine now, so I don't run any test on this patch, >> please take a look at this RFC patch first. > > You can test this by running a 32-bit binary on a machine with a 64-bit kernel. > E.g. on x86_64, compile a binary with 'gcc -m32'. Ah, thanks for providing the option, I can try that. > >> #ifdef CONFIG_COMPAT >> +static int f2fs_compat_ioc_gc_range(struct file *file, unsigned long arg) >> +{ >> + struct compat_f2fs_gc_range __user *urange; >> + struct f2fs_gc_range range; >> + int err; >> + >> + urange = compat_ptr(arg); >> + err = get_user(range.sync, &urange->sync); >> + err |= get_user(range.start, &urange->start); >> + err |= get_user(range.len, &urange->len); >> + if (err) >> + return -EFAULT; >> + if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(file))))) >> + return -EIO; >> + if (!f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(file)))) >> + return -ENOSPC; >> + return f2fs_ioc_gc_range(file, (unsigned long)&range); >> +} > > This won't work because f2fs_ioc_gc_range() expects a user pointer. You'll need > to make the native and compat versions do the copy from user separately, and > have them call a helper function that takes a pointer to the argument in kernel > memory. Yes, I need to introduce function like __f2fs_ioc_gc_range() to accepted pointer parameter which points kernel memory. Will do test and resend v2 soon. Thanks, > > - Eric > . >