Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp262425pxj; Tue, 18 May 2021 02:48:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKkGN+gW8sfyxraqpwd/JcIPivI+xo/Y8yR9HlSP/5wBPgjBJbgaVYAK1A+MyUQhbNsh49 X-Received: by 2002:a92:d0c3:: with SMTP id y3mr3497267ila.58.1621331331405; Tue, 18 May 2021 02:48:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621331331; cv=none; d=google.com; s=arc-20160816; b=bQL7QEUaokqddVnHNVvL8YMFNp6MpRy4lj26eJ8kA3xmVSoEsqG9X+gUa4aEF0cp+I uaMSBq2bUZKRlLmifz9GCDU2pXNACf0w9/K5HyR/f946OS5lKh+xxdpxOsMi/V49hjdA F0cGOYH7XJG4fGViGI3dUJkHNaJ3Nmc20ZjNSEGn8fblAiGH91K59p6mYQiHA5p7yXFC KOS8PCo8q5pU+p+3v7cnaDaL4wEeML0m94q+xSolhaUJLsCu6Dv2N4TYGoXJqttm+z1h ioesYUdoGksODQ+NQwqtGj7lElnKiPUsinjtxEzu0b2MqPwR3ub6ge2/BnACV+kNLez2 C5Cg== 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=ql5o3eq0/p59sdeVXSUOqcsElZYOOpUdKixFXAcAGI0=; b=Byq2sexYfjRB5wNJbyLoCSPyK+v/RaBYmQOnNN2RuN6kzEPTidTFXAFV9QeNmVeOIt oTzLNIlMu0I1PHPxClAb6XmkKI+E4/PzyhbKJNAn+PpKoFUmyl/+lYfAmx7vlLoZet8q x+uqG8ye6XG0RdKRCWV8o9Glb8ciPDSp2FrNbl3rnwAbBJ6rAh1nB3M7K8jyVZnVq41Z iFFOzlFFq1I8wyxRemF8HoJ5kaSyg7cWGl2WM8wlGb4gvJ2NQN5BqHZu6VmXN8HFGCl8 G8CXgSZQT+0DIr86iJ8WMib3AMYK9V0ABLW/SFdkpv6a7X6aj+gEoA8P1fsv3QP/WmaD 9qrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="hKy/MACY"; 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 y15si16776221ilj.128.2021.05.18.02.48.38; Tue, 18 May 2021 02:48:51 -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="hKy/MACY"; 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 S243106AbhEQPJM (ORCPT + 99 others); Mon, 17 May 2021 11:09:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:60758 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241869AbhEQO66 (ORCPT ); Mon, 17 May 2021 10:58:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 29090619C5; Mon, 17 May 2021 14:26:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261578; bh=pyn+/m4aVgxvspKig4Y6l3QquMjk4ttRmzC4p2+opf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hKy/MACY2TDELNt3oxvSn+qoWyFDJyVQRjNU98iBuAGX0Ec1FX+VPEyd3g36DcPGh IyzmrS8V7C3DKWjHCj99iK5KyrTAVRMZD5YRcuiTXhmpa0WQvOPqB8/Mo0d4+vRRUc +b4Z07y50gzpQqyg23ksGTCQQQVeE8Bhwd5x/cFo= 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.4 061/141] pNFS/flexfiles: fix incorrect size check in decode_nfs_fh() Date: Mon, 17 May 2021 16:01:53 +0200 Message-Id: <20210517140244.822185482@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: 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 1741d902b0d8..fa1c920afb49 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c @@ -103,7 +103,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