Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp147296imu; Thu, 6 Dec 2018 17:35:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/XZoCFqT1s4U4Jl+NLSVVkngGrud8a5Mylm0Cbrez/Zo/qla41Jw0BnH8ijmld9e7aE9bpw X-Received: by 2002:a17:902:f44:: with SMTP id 62mr305254ply.38.1544146532959; Thu, 06 Dec 2018 17:35:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544146532; cv=none; d=google.com; s=arc-20160816; b=mOqpHhAc//WkG/VPM1vc0SMPJhCXWO5U4FrkyKCUCyf8xGR6ipIa/o7oDoXPYXMd00 RAiexZCS7unUH3A4drIN/hYY1aXl+Lfjx36HFd+kc6UDULbOkcKqyWIKtoXup9+ILQWT e+7cKWAxRKfRa3vxiOwaGMrOzv81PwG8Tct2oTBz6ADiZuFW37w/HnYgpUiKO4LiMaES ZTLhocklS+DpjdSqL64UjfaZ5mmzuNV8u5rbYh+IyAb+ZbCGTOMQ56aqmwZbbbteIq36 0KCTIx4Ve5WEGW2tbyWTZsS5NjmlAl6coX+jrGq0nimwMCMiJmB8cH7NEnOLJVv0ngF5 6jTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=nXcyb4wVOdunexeWebf188Q6PWPhmCn4fAP7SIU9vc4=; b=Vx8O9Xud52coclzbwr8B8iJE+BoDpGkcKHDUVxXBoahyX5Dfa1LfAFnQ4sKnUZWPmV pp9RLNFF/ygbTVrB84uEhN9+IG5RacsrlyjlER6cOmjTS468+bA4aHvqA0q5FEBJO9/5 V4nWw1OLFu7wQrmlhudNlNAl5Txh92Kp0HnSr0FU3cJl6jNSfNvKLxyg/qWlX+rQazSU Z9H9z5P/kU1UO4aMRhmbNsSF82HYgse3gj//cSxcY+lfjP8BqCxrhpR6mC3E5kPJvDbg 9zNzkLzm+Ja8IP3KYLCtW4bfCrc3TvaHDybjzLM5920lltZipOW/j2EiGavU86LqahsK D0HA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si1573041pld.331.2018.12.06.17.35.05; Thu, 06 Dec 2018 17:35:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725978AbeLGBeO (ORCPT + 99 others); Thu, 6 Dec 2018 20:34:14 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33911 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725939AbeLGBeO (ORCPT ); Thu, 6 Dec 2018 20:34:14 -0500 Received: by mail-wr1-f68.google.com with SMTP id j2so2331928wrw.1 for ; Thu, 06 Dec 2018 17:34:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=nXcyb4wVOdunexeWebf188Q6PWPhmCn4fAP7SIU9vc4=; b=ZvfKfpX+L4CMqTwV8k6ubNVbK1puXL04wWMMcMjdk24LQrb2aKs+A8Nkh5IPiH4jpz zqVx3XunlOdsmeWIErz5NbynxqAVsn0gPmlGNP2/Ni3CJw3GDxyK0/zrGwQr78Hm1Y7u rjgRk+1gGB/LDHssEVygRdIM+LDIIp0RafZgFbN3Sqh18Kea9q651+V/f9qAAVM8ghwY G3yb2yHJsQDF+qGBA5bPhvdpgg/PeRIa+5s27T8Khh+iaMLfBAao8fvRwjVVR8xvJJPI 0nZijYPbaZ5hbkE1C8EkRnWuizItM1vkQCZ8bdFyMNCsJ6Pm/r+R9U2zMo7jbRBKOEng mVwA== X-Gm-Message-State: AA+aEWZvDcQ/5M/f1f0eSnHmzYj2Q18d1sZgoBscxJSq4iA6xVkghnYh AldRobciqb+oFl7qtT6VzNG70N9gKHo= X-Received: by 2002:adf:f009:: with SMTP id j9mr185460wro.170.1544146452018; Thu, 06 Dec 2018 17:34:12 -0800 (PST) Received: from raver.teknoraver.net (net-37-182-2-241.cust.vodafonedsl.it. [37.182.2.241]) by smtp.gmail.com with ESMTPSA id j202sm4815675wmf.15.2018.12.06.17.34.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Dec 2018 17:34:10 -0800 (PST) From: Matteo Croce To: OGAWA Hirofumi Cc: Timothy Redaelli , linux-kernel@vger.kernel.org Subject: [PATCH] vfat: don't read garbage after last dirent Date: Fri, 7 Dec 2018 02:34:10 +0100 Message-Id: <20181207013410.7050-1-mcroce@redhat.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The FAT32 File System Specification[1] states: If DIR_Name[0] == 0x00, then the directory entry is free, and there are no allocated directory entries after this one. The special 0 value, indicates to FAT file system driver code that the rest of the entries in this directory do notneed to be examined because they are all free. This is not enforced by Linux, and is possible to read garbage if not all the dirents after the last one are filled with zeroes. [1] http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/fatgen103.doc Reported-by: Timothy Redaelli Signed-off-by: Matteo Croce --- fs/fat/dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/fat/dir.c b/fs/fat/dir.c index c8366cb8eccd..0cec89271349 100644 --- a/fs/fat/dir.c +++ b/fs/fat/dir.c @@ -588,7 +588,7 @@ static int __fat_readdir(struct inode *inode, struct file *file, bh = NULL; get_new: - if (fat_get_entry(inode, &cpos, &bh, &de) == -1) + if (fat_get_entry(inode, &cpos, &bh, &de) == -1 || !de->name[0]) goto end_of_dir; parse_record: nr_slots = 0; -- 2.19.2