From patchwork Sun Nov 29 02:01:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=bpCWmEFl; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBVz3NZkz9s0b for ; Sun, 29 Nov 2020 13:04:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1A10682788; Sun, 29 Nov 2020 03:03:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="bpCWmEFl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 05F0182779; Sun, 29 Nov 2020 03:02:53 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5E30D82741 for ; Sun, 29 Nov 2020 03:02:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615348; bh=1ZVVRxFg4GJkxr90o4JFPHOTH/6VWYqqoNj/d8H2zpc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=bpCWmEFlUL4nCCXyY+ub5zvXa7VEcpFs/QEQIJy0Cjh4imzLX2XHeE41g3mKCnwOL LpJmyRV8wwsOWBUnlSdQVWH4ChPjp/QqwvHMdqHGT7QKcWGHIkojvhZoi9d/8ZOdR2 PxSrTgxX99D7o3XBegCLNSfZxgzcBdlv08GkEpaI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MUosN-1kaDlV2eO1-00QiD6; Sun, 29 Nov 2020 03:02:28 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 01/18] fs: fat: avoid NULL dereference when root dir is full Date: Sun, 29 Nov 2020 03:01:59 +0100 Message-Id: <20201129020216.4865-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:7VpDXhZCYbC3KsZJGSFunf0fpQzDsweBKohpq1PHZohCTHvufUO bguApBtobswtSvL1zlTEhE92WvJiamyM71aTOepVAQQdrtCI11bxPG14pHrU147IJ0pvG8R c6h8DTifI+osd0YBEpiGvBluEcS19qVZ3pllGMbv8hV69wwstF0BLqTd9aYxUOKKzp8f3cG Mu6V0gxF8EyCKlTAJWWSg== X-UI-Out-Filterresults: notjunk:1;V03:K0:nzSupXHOOfs=:0PDvaJWsz5DWGpPJXJoCdO 4QH29upTwz1IkUG2bQKzZpSwZwdmJRgFVRMDFEeqdcsfCvyCSAE9KG2Jex2HN40v0VZwE/G8n voT3GdaB5ry2gJDgBgQJYubmq48ixYDIYEVFIRqyAcaaa80OdIBhHSAM9YZdDxHBW63CPo4W3 XvrEKzrq8TlgslrrDGbVsUDi2gthZUcwXc+Jp5WnAWUJTdBuXtJBmpPjW6A0uCzu9SJ5mGjJ7 nnFxBbwj7au5twfZU5DeBQD4QBW+16Txm27f2fgSBp56ROKdNujh4d1HNqat8wRz8oYa9QEll GDG5DkUqP0NDPV9SicHfGd0qFyHPx4TteWr8hjstFHk8QJZ5C/D4m5du4J/wXD8oHV0FnvqMP y0ECJQg0VCXIYANzH5h2jNWLKyMrK22TBG+rcZqOC+EPwCKpvs8qvH5BSdljnMuxDGschDfc0 nbmzvpNxEflJ/QrLH6JhIkG3KeZDhAaZsCAuRNnuhD8Bpf7u8LoaEBWBs2wmXgOgTlzifykH/ lsFSiRVaO7NlLDemZwld5LeTSfleKvoj7QKOnUqMMLWj34jCco7fNuFAk4zcEzg89TAHK0Wog 2auMtELr5QUH0MdmaAB4FiZffCntWa2JtsCmdpaykYE3MSOj39CnT8o0Rzm1GvPP9UC7lTVrq WOkEV1HOnYEWB1/Rp6mq/CBmY2SQGuAUPHS5niioFL7c7qsZu1SHp+6P6AxL/L9r62ttlmDMV V02X2t2cxoNNhlBae9oKcNd8ZKHRdFijyftFr55NV37y1tOSP2UVrtRBOv1Oq9pgpqHhb6Wkw D/HwVSAu5UybbVADTvBclD8E79+mYGwRSM2Y6O1IWeYPVkdVHFU9EuJwhTY9MVD4YjTx90uKt aocwk1BnPnM2nZAOIA9g== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean When trying to create a file in the full root directory of a FAT32 filesystem a NULL dereference can be observed. When the root directory of a FAT16 filesystem is full fill_dir_slot() must return -1 to signal that a new directory entry could not be allocated. Fixes: cd2d727fff7e ("fs: fat: allocate a new cluster for root directory of fat32") Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index a2682b5f46..fc932df953 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -260,9 +260,8 @@ fill_dir_slot(fat_itr *itr, const char *l_name) flush_dir(itr); /* allocate a cluster for more entries */ - if (!fat_itr_next(itr)) - if (!itr->dent && - (!itr->is_root || itr->fsdata->fatsize == 32) && + if (!fat_itr_next(itr) && !itr->dent) + if ((itr->is_root && itr->fsdata->fatsize != 32) || new_dir_table(itr)) return -1; }