From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C83CC433DB for ; Wed, 23 Dec 2020 10:01:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0D192246B for ; Wed, 23 Dec 2020 10:01:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728309AbgLWKA5 convert rfc822-to-8bit (ORCPT ); Wed, 23 Dec 2020 05:00:57 -0500 Received: from lithops.sigma-star.at ([195.201.40.130]:34410 "EHLO lithops.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726022AbgLWKA4 (ORCPT ); Wed, 23 Dec 2020 05:00:56 -0500 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 00029625DE06; Wed, 23 Dec 2020 11:00:13 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id PvEedl0pH8YN; Wed, 23 Dec 2020 11:00:13 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 85EB3625DE07; Wed, 23 Dec 2020 11:00:13 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id X7jk5AndnOpC; Wed, 23 Dec 2020 11:00:13 +0100 (CET) Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lithops.sigma-star.at (Postfix) with ESMTP id 591BE625DE06; Wed, 23 Dec 2020 11:00:13 +0100 (CET) Date: Wed, 23 Dec 2020 11:00:13 +0100 (CET) From: Richard Weinberger To: Chengsong Ke Cc: Sascha Hauer , linux-mtd , linux-kernel , wangfangpeng1@huawei.com, chengzhihao1 Message-ID: <135307670.158287.1608717613022.JavaMail.zimbra@nod.at> In-Reply-To: <20201223062808.27512-1-kechengsong@huawei.com> References: <20201223062808.27512-1-kechengsong@huawei.com> Subject: Re: [PATCH] ubifs: Fix read out-of-bounds in ubifs_jnl_write_inode() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-Originating-IP: [195.201.40.130] X-Mailer: Zimbra 8.8.12_GA_3807 (ZimbraWebClient - FF78 (Linux)/8.8.12_GA_3809) Thread-Topic: ubifs: Fix read out-of-bounds in ubifs_jnl_write_inode() Thread-Index: z+tkpY/z0vMi1cpMRZMXcPO+z7DtJw== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Chengsong Ke, ----- Ursprüngliche Mail ----- > The memory area allocated in ubifs_jnl_write_inode() is not aligned with 8 > bytes: > ino_start = ino = kmalloc(write_len, GFP_NOFS); > > When ino_start passed into write_head -> ubifs_wbuf_write_nolock: > n = aligned_len >> c->max_write_shift; > if (n) { > n <<= c->max_write_shift; > err = ubifs_leb_write(c, wbuf->lnum, buf + written, wbuf->offs, n); > // Read oob occurs here, read n bytes from buf, and buf is passed from > @ino_start which is > // not 8 bytes aligned(write_len < n). Program read (n - write_len) more bytes. > } > > Reproducer: > 0. config KASAN && apply print.patch > 1. mount ubifs on /root/temp > 2. run test.sh > 3. cd /root/temp && ls // change atime for link_file > 4. wait 1~2 minutes > > Cc: > Fixes: 1e51764a3c2ac0 ("UBIFS: add new flash file system") > Link: https://bugzilla.kernel.org/show_bug.cgi?id=210865 > > Signed-off-by: Chengsong Ke > --- > fs/ubifs/io.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) Good catch! Please address the problem in ubifs_jnl_write_inode(). The length there needs to be properly aligned like all other journal functions do. I think you managed to trigger the issue because ui->data_len is not aligned. Thanks, //richard