Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9043661pxu; Mon, 28 Dec 2020 05:15:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJyCOju/+WrcrHkORqrJsXywgeGoXXEYMkSpluoTsB6rStDwP1asGHacU+Grzx4RDxZw4bNu X-Received: by 2002:a17:906:f9d7:: with SMTP id lj23mr42638540ejb.266.1609161327792; Mon, 28 Dec 2020 05:15:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609161327; cv=none; d=google.com; s=arc-20160816; b=vckgnpjC4eM7dPdbM/RH0cIxHYqmqrLfi1817SjwqFz1IjYe/qNzVSxP4Tdywk0pWU hjY2lYPp+CmtUY8WStDCZ5y8j8fx4KulFCDU3c5zk8nCNkVC9WZobl1woGQqm+WDSLnA gdsPA0F/Uv/uCh/qDOMqnAnDLxhhRxnZrzYtUGnK6Gqs4D3ekeq2eL5IN7AqMan7BY5j xdNLgmKF6FQ7Hc/C5KzPxGsOB0QVbI5gxinicrZM/LRbnW04xvUpF+FU/Y3he7hPEuMy JoZLg5SC/BV2tdaPDtVgVISLs9okg9VT8iTGIsyRZevU9UFdh5gnNpE/e1S7VmWJaMB9 iz9g== 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=uyJ9FcKoi1xfsUZocpktYp3TAJHJxTydVPSjlhGbuFc=; b=dzSAZHudVq2s9IMfrGn+60eJrxiy+9jTCx6vcX6OyOE2Z5jw+9Hz1zxCB1ODcYLrWv 0cmzSeL1a+WLsjDOm4v2riRS6Sb9iOHzcjrowejNjROwS4funocQTIuC2x0TMD56kUsX CkKHWXbbcUayeB/UtungsAUKf2L2heVNpLm+VcaYi8LS81teaHYoM3TsUf+di+HxvGHL Bh2EWyiOKnLWInKoIURnsls6yk5s8fdWms0vFzDmv9hVm4ZSoASrvzGMX8GZeSsejclv YWAfo4TYw4A2wFnWBlSe+/EdGjh1mJwL4UNHTUaPQZQF/BaELeCBKB8fBHRl18dHRT/I akGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EytxmuFs; 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 b2si12933936ejc.551.2020.12.28.05.15.04; Mon, 28 Dec 2020 05:15:27 -0800 (PST) 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=EytxmuFs; 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 S1729632AbgL1NLy (ORCPT + 99 others); Mon, 28 Dec 2020 08:11:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:38048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731375AbgL1NKX (ORCPT ); Mon, 28 Dec 2020 08:10:23 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0253A22582; Mon, 28 Dec 2020 13:09:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160982; bh=RoysQs+gxXGp63xNUERVOgDtnxepKhU9f5tOZDw9G7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EytxmuFsiz6lfvtH2pz/lFIILUfsiBHvrIUvumUm9KbTkMrgLzKWlZhGRXMYukgjs A7l0Au3+DXosh3X0Ny4wZqBdavrjWdMMi2RG3eHIRDtQ7s/X5ajm/+Pwn1I6sIQtf3 m5WBvfwlLO+lyi1sJcWqiBbFOlBLdcB4FO2hqv2w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+f816042a7ae2225f25ba@syzkaller.appspotmail.com, Andreas Dilger , Jan Kara Subject: [PATCH 4.14 060/242] quota: Sanity-check quota file headers on load Date: Mon, 28 Dec 2020 13:47:45 +0100 Message-Id: <20201228124907.634285755@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@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: Jan Kara commit 11c514a99bb960941535134f0587102855e8ddee upstream. Perform basic sanity checks of quota headers to avoid kernel crashes on corrupted quota files. CC: stable@vger.kernel.org Reported-by: syzbot+f816042a7ae2225f25ba@syzkaller.appspotmail.com Reviewed-by: Andreas Dilger Signed-off-by: Jan Kara Signed-off-by: Greg Kroah-Hartman --- fs/quota/quota_v2.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) --- a/fs/quota/quota_v2.c +++ b/fs/quota/quota_v2.c @@ -158,6 +158,25 @@ static int v2_read_file_info(struct supe qinfo->dqi_entry_size = sizeof(struct v2r1_disk_dqblk); qinfo->dqi_ops = &v2r1_qtree_ops; } + ret = -EUCLEAN; + /* Some sanity checks of the read headers... */ + if ((loff_t)qinfo->dqi_blocks << qinfo->dqi_blocksize_bits > + i_size_read(sb_dqopt(sb)->files[type])) { + quota_error(sb, "Number of blocks too big for quota file size (%llu > %llu).", + (loff_t)qinfo->dqi_blocks << qinfo->dqi_blocksize_bits, + i_size_read(sb_dqopt(sb)->files[type])); + goto out; + } + if (qinfo->dqi_free_blk >= qinfo->dqi_blocks) { + quota_error(sb, "Free block number too big (%u >= %u).", + qinfo->dqi_free_blk, qinfo->dqi_blocks); + goto out; + } + if (qinfo->dqi_free_entry >= qinfo->dqi_blocks) { + quota_error(sb, "Block with free entry too big (%u >= %u).", + qinfo->dqi_free_entry, qinfo->dqi_blocks); + goto out; + } ret = 0; out: up_read(&dqopt->dqio_sem);