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.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 A209CC433FE for ; Wed, 9 Dec 2020 18:13:53 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2B2CE23C1A for ; Wed, 9 Dec 2020 18:13:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B2CE23C1A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kn3yJ-0007fQ-NH; Wed, 09 Dec 2020 18:13:51 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kn3yH-0007fI-IA for linux-f2fs-devel@lists.sourceforge.net; Wed, 09 Dec 2020 18:13:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=BPpiVwJwbCA/SJkH1A30g3V3EvTXlK0B5wY4Rt0mSqQ=; b=DG5y3IPXH6amOMAkwq8M9h/NAi qS6Q0ZWYS788nOOkobeE2XmdiMptwXKjuJ+DxDV+BqY4bDYnih9nj178aZzBLIp/Z0hTgtNM2MVnJ 2358QnL6CMkkP1RYic8mW3DKYy1nzo6o52l84hTGaBdIVJw/f0sCEoY+BuQFLepgS39Y=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=BPpiVwJwbCA/SJkH1A30g3V3EvTXlK0B5wY4Rt0mSqQ=; b=m nrHNxi1itZap94hVkUUr9g4xt/GgzhdmXgWf9fDbKQpOrWG9iJGGFvgpn/y50uvI/g5o23kOblqSu 3F7JKkViWQY0QubXgjUEx6u10DcUcBuOZyHwNbBlwevfV6DcYpfELxscE6JuQfkVdDhPzVYSvOhrU dPU6pQ4e+07nkAaw=; Received: from mail-pj1-f68.google.com ([209.85.216.68]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.2) id 1kn3y5-005Kk2-Mr for linux-f2fs-devel@lists.sourceforge.net; Wed, 09 Dec 2020 18:13:49 +0000 Received: by mail-pj1-f68.google.com with SMTP id j13so1420587pjz.3 for ; Wed, 09 Dec 2020 10:13:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BPpiVwJwbCA/SJkH1A30g3V3EvTXlK0B5wY4Rt0mSqQ=; b=Zev595F216Rc3TBUQGuC7gFiQSKi3xmHZh9VbmYr2J0aZ/2J4H0gNmA8rAoP2iJxzw XQ01BR8WSQPUviY2uVghZHY9gDSWP4KGi2xuAkF+QfYdzx8EPAUSIXFZYG+p/KsREBql KuSlbePTtq1SyObqovFY8f6hdx2QKVK4ZLD0YMotel1p/8OBlAg4nm7rzar9GAKcATnU 4PjK6uNuC8rYwtxW6ICdinsGM39GvkgviGaovxs5BShJsXa3SFqh4Z4MCZXPYBAI4mK9 Qj1DxRlkSnGKf7v179o+nfd9tOmE5D7lf8LitLofCqkruylF/PsLMJr/TEdiwOHvRzsA UYCQ== 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=BPpiVwJwbCA/SJkH1A30g3V3EvTXlK0B5wY4Rt0mSqQ=; b=TalTz0FFgeQ461c7Zjsz5Ctpfrxzv9WHhxsTD9ab9esd2ms/mTktSTlPWALVKjDT2y PDzzkaDvSuG/7sUOaIP0L+Txl4Go+Sox6ulRBtN7h6dqkaDqlVA2re1j3wSpCgbX4KBu Xt2Ahyf6wgFf+F+gP07SUiwmmo2VkRMxaYzbubP9r/RE8yyTHZ1f3apm6n+i7gCCdoxC jluecD5ebj/mClyCLDi8F/Zkmugg34guh7wq1e/PnpMdBs4nI19K+Vw8Mth0E4HT9Fef slcT4B9RnHrxmCDh4SIA+i8CEaajV6UkYS7LOaERwn5g0RfV8k43kKuzPgZlPCkzaRUL 2t+A== X-Gm-Message-State: AOAM533uhe6sQNO4vCYsKT/aIRJcs8ZVmakBcSS2oUxP7wn0PjxRwoEu 1k9dwwjsH32X/dFXuiuIRxo= X-Google-Smtp-Source: ABdhPJz+LnsD+M/2QOtOCDI6Djqe7Vn94N8UA5khAEi/S9ljjHipC9M2D+eY2yr4Pj2X1gTSa4KG3g== X-Received: by 2002:a17:902:63:b029:db:c0d6:96ec with SMTP id 90-20020a1709020063b02900dbc0d696ecmr3262997pla.13.1607537610507; Wed, 09 Dec 2020 10:13:30 -0800 (PST) Received: from localhost.localdomain ([49.207.201.111]) by smtp.gmail.com with ESMTPSA id p21sm3078636pfn.15.2020.12.09.10.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 10:13:29 -0800 (PST) From: Anant Thazhemadam To: Jaegeuk Kim , Chao Yu Date: Wed, 9 Dec 2020 23:43:22 +0530 Message-Id: <20201209181322.27932-1-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Headers-End: 1kn3y5-005Kk2-Mr Subject: [f2fs-dev] [PATCH] fs: f2fs: fix potential shift-out-of-bounds error in sanity_check_raw_super() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: syzbot+ca9a785f8ac472085994@syzkaller.appspotmail.com, Anant Thazhemadam , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net In sanity_check_raw_super(), if 1 << le32_to_cpu(raw_super->log_blocksize) != F2FS_BLKSIZE, then the block size is deemed to be invalid. syzbot triggered a shift-out-of-bounds bug by assigning a value of 59 to le32_to_cpu(raw_super->log_blocksize). Although the value assigned itself isn't of much significance, this goes to show that even if the block size is invalid, le32_to_cpu(raw_super->log_blocksize) can be potentially evaluated to a value for which the shift exponent becomes too large for the unsigned int. Since 1 << le32_to_cpu(raw_super->log_blocksize) must be = 4096 for a valid block size, le32_to_cpu(raw_super->log_blocksize) must equal 12. Replacing the existing check with the more direct sanity check resolves this bug. Reported-by: syzbot+ca9a785f8ac472085994@syzkaller.appspotmail.com Tested-by: syzbot+ca9a785f8ac472085994@syzkaller.appspotmail.com Signed-off-by: Anant Thazhemadam --- fs/f2fs/super.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 33808c397580..4bc7372af43f 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2775,7 +2775,6 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi, block_t total_sections, blocks_per_seg; struct f2fs_super_block *raw_super = (struct f2fs_super_block *) (bh->b_data + F2FS_SUPER_OFFSET); - unsigned int blocksize; size_t crc_offset = 0; __u32 crc = 0; @@ -2802,10 +2801,8 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi, } /* Currently, support only 4KB block size */ - blocksize = 1 << le32_to_cpu(raw_super->log_blocksize); - if (blocksize != F2FS_BLKSIZE) { - f2fs_info(sbi, "Invalid blocksize (%u), supports only 4KB", - blocksize); + if (le32_to_cpu(raw_super->log_blocksize) != 12) { + f2fs_info(sbi, "Invalid blocksize. Only 4KB supported"); return -EFSCORRUPTED; } -- 2.25.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel