Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp395339pxj; Thu, 20 May 2021 11:49:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyblLOVHDz4hh9mnBX283cEHQuH9/gYrVURR2LMq9pe/UWi8S6pW2m0ZfiIQEcZsuRUmjj2 X-Received: by 2002:a02:c73a:: with SMTP id h26mr8056981jao.95.1621536546306; Thu, 20 May 2021 11:49:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621536546; cv=none; d=google.com; s=arc-20160816; b=Bc+vHDSmint1I1nh0FCPaDs5Br/lqZVz7jw0NVNCExMVNikWLNg+HaEruxmgiCoeX4 V0KZQPnhuvnfutxdAY7KbrDpqotaC6qNUyUlwn6Bqw2GLGmWhR6kxELe8zSM1GQttEKJ jYBfhSpZyIjyuaGiv0viLd+r0LCpWXUeDbzyGgGLZj8arADEXSLqC9SmP5IedNuoRIDs 0FI4275RftUZYeuR3JxElMCxnDQu0O72ZoKt8/AcxddIvMzcGrymRXlp+bOufyPFKnd9 gqtb8WjzHWtBxjXiRBe7JQgKCB7402B/k6/Gu9hnpYGc6JIbh4o5EzzPx9ObrY69ymp1 itrA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5EGyBpxArOHxGfZSsTRjCHw3L63dCs2qbAKptAacKJU=; b=xUqi/pkDHTtVLChqBElVj4wKqkAUJxjQvocnotEBRz9qn42mccEJaxe2OsyyYhBldj AWBtwO7+sBM3rIf3bOvZLnaghSV1L1moGIeuSOl0d3KbTufMcQz7BapmUqJQrTeNwGuT DgJJUnT+Tb5h30X7aDxvQecYMoAJ3qa53uHmtX58o/TtiKRhT/wV72JjhFO28/ZYL8PN PzX31LvkXpwXqi5t2nhaMVRgODP6MU1/SyIHlp0QsJCXnDiDeJsnnjgeRgRjbIhKeI/J MEWGQcQKvnnmCLwk9PwiZU6556ONWuuyF9KC3QgLW1cldhQ9MIt+Ie/UDYC/hcthgbsF MKYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ExTMd32n; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k7si3029221jaq.89.2021.05.20.11.48.52; Thu, 20 May 2021 11:49:06 -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=@linuxfoundation.org header.s=korg header.b=ExTMd32n; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235760AbhETKXD (ORCPT + 99 others); Thu, 20 May 2021 06:23:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:43020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235678AbhETKL4 (ORCPT ); Thu, 20 May 2021 06:11:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E9B4161970; Thu, 20 May 2021 09:43:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503818; bh=qgA/fXD4F6Koj9VdCi58OxcitLjK1laDKud+WmMKar8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ExTMd32nOyP+0gw+114MR2+gx6/+PhUJbI/v76Id3M4VSXOCpdDvKWphqc41nFj35 3CaaAmlbma+kKLaL8Rv2Hm6MQ83TrryGfR277BQ9RaaFfGZ93O9JP09ZjdLSnwP2MS umwL4PuEGkR6aA971WsVMJsufGX1HxltZauh1qJk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Phillip Lougher , syzbot+e8f781243ce16ac2f962@syzkaller.appspotmail.com, syzbot+7b98870d4fec9447b951@syzkaller.appspotmail.com, Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 366/425] squashfs: fix divide error in calculate_skip() Date: Thu, 20 May 2021 11:22:15 +0200 Message-Id: <20210520092143.434989600@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Phillip Lougher commit d6e621de1fceb3b098ebf435ef7ea91ec4838a1a upstream. Sysbot has reported a "divide error" which has been identified as being caused by a corrupted file_size value within the file inode. This value has been corrupted to a much larger value than expected. Calculate_skip() is passed i_size_read(inode) >> msblk->block_log. Due to the file_size value corruption this overflows the int argument/variable in that function, leading to the divide error. This patch changes the function to use u64. This will accommodate any unexpectedly large values due to corruption. The value returned from calculate_skip() is clamped to be never more than SQUASHFS_CACHED_BLKS - 1, or 7. So file_size corruption does not lead to an unexpectedly large return result here. Link: https://lkml.kernel.org/r/20210507152618.9447-1-phillip@squashfs.org.uk Signed-off-by: Phillip Lougher Reported-by: Reported-by: Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/squashfs/file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -224,11 +224,11 @@ failure: * If the skip factor is limited in this way then the file will use multiple * slots. */ -static inline int calculate_skip(int blocks) +static inline int calculate_skip(u64 blocks) { - int skip = blocks / ((SQUASHFS_META_ENTRIES + 1) + u64 skip = blocks / ((SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES); - return min(SQUASHFS_CACHED_BLKS - 1, skip + 1); + return min((u64) SQUASHFS_CACHED_BLKS - 1, skip + 1); }