Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp338942pxj; Tue, 18 May 2021 04:42:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxoUIaOz5cTuk8JyGJ0CrKiMFtKX0MhdgZBTTlX/G6ZNfGUCSTBoU/h+zeRkJhN3iNovTC X-Received: by 2002:a17:906:1e0b:: with SMTP id g11mr5579418ejj.291.1621338141634; Tue, 18 May 2021 04:42:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621338141; cv=none; d=google.com; s=arc-20160816; b=GM08eEeFzAiDoe5jQCTcSYEoHIxJNMHPMk8K5N59O1OUlAB/IPzEnc8sMMl0TLbPQL aC4f8ZcnV9yHirnXS3qDHXoGlTTXNh8DMXO82cx/l5SC+gm3eMxT0JoOu3qc2yPpiP0J oL3tv6Csr3bGL/QHl/9dW7dv1F0Svnv9JlMtE/2VCCGyjOyGZqScwWS7DocbFsRMi6mr TZs2yYlDk4Li4hnOpT/zLCTumOyiuWUJLySJ/k/RZhZXEV2qDZFgSPsiqBD8kV30+4ay o6dg1vKlbViVj5A3sw9uupeKsy9e0vMSNISX/roP8c6p45dmCTEOIE+j9BLjKVkN4yOA qKaA== 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=1+bweaprJNKvoynjVuHF+iLaj1pbRbQLNstI1QRKDk4=; b=0YG/gLdItO7/eo3Vswg95Sc3BXiizyYYjzmtv3wM+zeo8B3Xy+xiAwn3N+dGETHJQT N6qqV/F+QvkHFuDno8+cwh6jxtn8YvJU5qjcqxs3/0EHOULcl5PQSxXkkLPOADlEnaoy /83oPQPZuaU6ejS3pX4y2lQGr8lzn/3e6R5xN5i74Xw8bFueuDGVhI/0yiCI0QmqJCxC Hrdjd/lxIjNFi8d/lVDkOVTchR7yl3/Jj+uK9HonAgR5KPH7PAPpiE3BG3TtYhAjAFOJ MGR4Ze9s4Ret5xKXJ40wC+dbgjftYXCzmRaeEMSzbW0TQGwV234LwVUHzmHkBY4Jvmsl ITMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M0LnMkan; 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 w16si3337507ejv.219.2021.05.18.04.41.58; Tue, 18 May 2021 04:42:21 -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=M0LnMkan; 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 S243657AbhEQPYC (ORCPT + 99 others); Mon, 17 May 2021 11:24:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:37322 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236513AbhEQPKg (ORCPT ); Mon, 17 May 2021 11:10:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A39CB617C9; Mon, 17 May 2021 14:30:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261851; bh=YtWrpDksy16CNvy7ZUAIzG9IVLdgDnmTWjRg9TIdu1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M0LnMkanX+1xdOjbeQ2fme6yZbc0g+Y2RYdicLYW1bHyvglMKjLh/xK5JYqH3MJ8Q b2EwoL5xczA4ItNJadlrXwWKdELY8k7Fx/0C/QfY4Zqx7Sg9r+HkZk7RJ4Ju881e1t 5U3C7O9SweSkgVqucBqE0iWMN1Rbd5rDp+7WrPRA= 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 5.4 100/141] squashfs: fix divide error in calculate_skip() Date: Mon, 17 May 2021 16:02:32 +0200 Message-Id: <20210517140246.140094345@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140242.729269392@linuxfoundation.org> References: <20210517140242.729269392@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 @@ -211,11 +211,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); }