Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3036633pxj; Mon, 17 May 2021 16:08:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/EBIDk0ry87sZLhAA/EEXGG2NGL4VbuMkia+GNjz01FWT2+rWbLwljz3xlgmK6V3PaWon X-Received: by 2002:a17:906:b2c1:: with SMTP id cf1mr2454445ejb.544.1621292929820; Mon, 17 May 2021 16:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621292929; cv=none; d=google.com; s=arc-20160816; b=FKt1meZumnp0813BS30nwj8mijnt9+VPPp4NMZsFM8Md4J5wjcgsqqnT3r9JHFeSSr 5hUGTA2RbZUP+efyGctdPStU0LE8oox6VqlRtPp0Bz9uTBBQElgXHZBwTkB9hhj2n91t nCk4iXKEQmOYMVJOD0kxHxbNR7t0FxLhmCqonznMQcOv9sKQ1h90y/JxPy0YzkDOC6VY 7si8JAkEoUoAkzU9+KJLd+qJDzjUlcddBAj2enfgho5BokjqOicfFLGTugrQ0v1AbYGi LD+LOW/WucYe1GW6QEuNlpFZLArihCbfgvVD1eizxDYGiWfH6hW3PmtpYnO7SrHqq/z2 XIkw== 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=Qzsk7zip0w2/AZe3dvlSF4NwD52oFkoZwwSmVSLZ+b8=; b=pjasOIExMRLw6nAVU3jGbWe9uVr5UaF/u2+ymB83ArEY0N+0K5gDlCR1mTjVynUqGk TsOzFl98X8rfzj6X7emZg9vGa5Cf62DHvkOaCm5LVPzD0iftI1h90MV00lY/UBLokyPc 5kvc6K2KYQ+taPF1wr1ZVw0roklrr1i4DZbPqwNHvB1yLe3bqZ3HcYWdh61O/zfAadXn Sf5V4GK/cpc3dltRvT3tYYYAdho6i8PgLMvW8UNYAmrRIjOyWNgjsXWP/D6tTNeYIl/h YW58dF/BWEd4MAhVJoBvIll6BX6bpvixa4ZncgTLS3IbYyv+bo0ov1reW25wH9d48sA4 ysvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1hlUDZK+; 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 l3si18045472ejd.313.2021.05.17.16.08.25; Mon, 17 May 2021 16:08:49 -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=1hlUDZK+; 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 S237113AbhEQOUs (ORCPT + 99 others); Mon, 17 May 2021 10:20:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:60192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238966AbhEQORc (ORCPT ); Mon, 17 May 2021 10:17:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 15DAE613FC; Mon, 17 May 2021 14:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260607; bh=1Ysj+Hxj23ymvQfvWfk3T8PrgjVs4FfUZeJurHBMO0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1hlUDZK+uteoKcozK4/cu/CrawxxEzWBGZIGxiYaNDm85jJL0/48T/TyL27q5z5Xo ONiASW4CeKP6yQ62lNSjLZZuZOEf/WrZW+nmnwD4+LiAC8ylhsNDHtRx+H7/wHVt7r 3JOOLz5J90oAA8iVhGBRrKfFHlNiKkF79rBWgu9Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikola Livic , Dan Carpenter , Trond Myklebust , Sasha Levin Subject: [PATCH 5.12 158/363] pNFS/flexfiles: fix incorrect size check in decode_nfs_fh() Date: Mon, 17 May 2021 16:00:24 +0200 Message-Id: <20210517140307.950084698@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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: Nikola Livic [ Upstream commit ed34695e15aba74f45247f1ee2cf7e09d449f925 ] We (adam zabrocki, alexander matrosov, alexander tereshkin, maksym bazalii) observed the check: if (fh->size > sizeof(struct nfs_fh)) should not use the size of the nfs_fh struct which includes an extra two bytes from the size field. struct nfs_fh { unsigned short size; unsigned char data[NFS_MAXFHSIZE]; } but should determine the size from data[NFS_MAXFHSIZE] so the memcpy will not write 2 bytes beyond destination. The proposed fix is to compare against the NFS_MAXFHSIZE directly, as is done elsewhere in fs code base. Fixes: d67ae825a59d ("pnfs/flexfiles: Add the FlexFile Layout Driver") Signed-off-by: Nikola Livic Signed-off-by: Dan Carpenter Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/flexfilelayout/flexfilelayout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c index 872112bffcab..d383de00d486 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c @@ -106,7 +106,7 @@ static int decode_nfs_fh(struct xdr_stream *xdr, struct nfs_fh *fh) if (unlikely(!p)) return -ENOBUFS; fh->size = be32_to_cpup(p++); - if (fh->size > sizeof(struct nfs_fh)) { + if (fh->size > NFS_MAXFHSIZE) { printk(KERN_ERR "NFS flexfiles: Too big fh received %d\n", fh->size); return -EOVERFLOW; -- 2.30.2