Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp849684pxj; Fri, 28 May 2021 18:12:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzA2WOxAsFGGcumtXN9x74B/cpSJ4nnF09F7wBqMvzr7CGIyp7r/5/z+0gOIW/T1qjOoA1r X-Received: by 2002:a17:906:4e8c:: with SMTP id v12mr11754537eju.365.1622250751858; Fri, 28 May 2021 18:12:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622250751; cv=none; d=google.com; s=arc-20160816; b=hikORSmSyHqaqQz1hu5dSPUelA678Drcy2gN1kNix3ZE2K5ZQRdFMf3TZcA0xaMEB9 4EGNMpokYFSrZCXPbB7z7x0nD+gnSUwUnmcYP20I62pRxghhy01sAVx8YJC1EiuT8GeB gH+WdlcREoG51YglsHEoNyT88Y0RSCcM+uMzQ6CcG4XLOEpAt2jOa/b3nW4G3Ja68pgR 30Np32DvE5RiBMZJfOhQgGPbS0aluCCyeskvuRQkBiTjBxwsBKTEXgVpLUFaZ5IqiYUm QN6x4e+MFIt62tAAppk17PZ3S0P7TPdlu1EsrEJE5wZZiNO5XK340P3SbqfosyLeJzgI XW1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:subject:reply-to:cc:from:to:dkim-signature:date; bh=+w5DrFGtQT7qGSjGuDnH/5/WNWgRUzVCn8cxpkKg+UU=; b=uZhIu/0p2fsIRb8XsQVBlTe0UMFQWTGUQHG6mwdVv98EOdIn2Yq4DXFbpYvJxOHLpi y0cyiH+q6fqw4eZzhKdbIrBFnvU65WFvxOPYBKtIJe93tGThx53sOaSEGDN4JWBqLLWc iWQKLcvY11l9OPObDy3U1wpNYIo1ixzoGUIfTctaKXTgPY8WhbbSpqoele1yQdNQTTSE gUi8JHKfTvZPA9B8/OIsL/NGQjrEqIVXqip9ybw51is6EOSs8pWWlAG3YK3ID3K9p+tV 7F/32ZN9ZgxwHHoie/EoDzDjJ8P5/OJ3xcA0CCUbNnWp2S2N/PWY4Rv69z7y/THFn7Wj qaGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail header.b=R9WETm0f; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr3si8475907ejb.641.2021.05.28.18.12.07; Fri, 28 May 2021 18:12:31 -0700 (PDT) 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; dkim=pass header.i=@protonmail.com header.s=protonmail header.b=R9WETm0f; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229635AbhE2BMG (ORCPT + 99 others); Fri, 28 May 2021 21:12:06 -0400 Received: from mail-0201.mail-europe.com ([51.77.79.158]:52232 "EHLO mail-02.mail-europe.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229597AbhE2BMF (ORCPT ); Fri, 28 May 2021 21:12:05 -0400 Date: Sat, 29 May 2021 01:10:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1622250625; bh=+w5DrFGtQT7qGSjGuDnH/5/WNWgRUzVCn8cxpkKg+UU=; h=Date:To:From:Cc:Reply-To:Subject:From; b=R9WETm0fyZJzkJ3UkIhI88VJVw2PneoVEsKtpATIg/MSMvGzx9WW/J/YwW0XLLhju w586zYWrm7sLSPr6V9af+jdYDQUAI4r9sbtk+FZbUx2wn62l/Htz2dz0mtbBEWy3tp ylZwW0a2r55zLl7TcHcxCkwy4RyfOxjDlc+NTflY= To: "namjae.jeon@samsung.com" , "sj1557.seo@samsung.com" From: Aidan MacDonald Cc: "stable@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" Reply-To: Aidan MacDonald Subject: exFAT unexpected handling of filenames ending with dots Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Namjae and Sungjong, Recently, I was made aware of a problem with how the exFAT driver handles f= ilenames ending with dots. Original bug report was against an audio player supported by Rockbox: https://www.rockbox.org/tracker/task/13293 Upon further investigation it turned out to be a Linux kernel issue. Note t= he audio player referenced there runs Linux 3.10 or so and uses some versio= n of the Samsung exFAT driver -- so I guess this has been an issue for a _l= ong_ time. I was able to reproduce it on my laptop running v5.10.39! It appears that any number of trailing dots are stripped from the end of th= e filename, causing some interesting bugs. The behaviour I am observing is this: 1. If creating a file, the name is stripped of all trailing dots and the st= ripped name is used to create the file (original name is silently discarded= ). 2. If accessing a file within a directory, the stripped filename is used to= conduct the search, ie. if you enter 'A...' the driver will actually searc= h using the name 'A'. It is this second part which causes problems. If you have a file named "A."= on an exFAT filesystem, it will show up in directory listings but if you t= ry to access it, you get 'file not found'. That is because the driver is ac= tually looking for "A" even though you think you are looking for "A." -- an= d even worse, if "A" does exist, the driver will silently access "A" instea= d! Clearly due to the first part, you cannot get into this situation without u= sing another driver -- like the exFAT FUSE driver -- to create the problema= tic filenames. (That's how the Rockbox bug reporter managed to run into thi= s.) Now, a function called exfat_striptail_len() in fs/exfat/namei.c is respons= ible for the filename stripping, it simply removes all the trailing dots fr= om a name and I guess it is the cause of this problem. So this 'feature' wa= s intentionally added in. I've only skimmed the exFAT spec but I can find nothing in it about strippi= ng dots from the end of a filename. The FUSE-based exFAT driver appears to = treat dots as significant too. It seems Windows suffers the same trailing dots bug, silently accessing the= wrong files despite listing all names correctly. But I obviously can't say= whether that is due to filesystem drivers or issues higher up the stack. To be honest I have no idea what the purpose of this 'dot stripping' is... = even if it was for the sake of "Windows compatibility" -- ie. mimicking Win= dows bugs -- there are names that Windows normally rejects which the in-ker= nel exFAT driver will accept, such as names with trailing spaces. Personally, I don't see any issue with how the FUSE driver behaves. It also= seems to be correct with respect to Microsoft's official spec. I don't see= why Linux should deviate from the spec, especially in a way that makes it = _less_ robust. I did search for any other reports of this issue, but it seems to be such a= corner case that nobody's mentioned it anywhere. Nor can I find any discus= sion or rationale for the dot stripping behaviour. Kind regards, Aidan