From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CA78C433DF for ; Thu, 20 Aug 2020 11:27:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46333208DB for ; Thu, 20 Aug 2020 11:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597922847; bh=DysMUwl484aGB1bJ1JQyqTW8i1SgBbgM8jezoFTjklk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=vs/nkdkz0h8w6CJaOnP8wvbbCH23n0j7mxA+MhiXor6zXAAAD16T4RLYvWuR3g214 yiQuHw/b9Qq5RPlgEs6OdLvzOUyNYABysCm8LiPy/c6W1EGyca2g5QzFdNyeJt5QR9 OEoHtP1iaQ7UoDkjtMkoRwNEE6vr+AXEtB7SbcU8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730189AbgHTL1V (ORCPT ); Thu, 20 Aug 2020 07:27:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:34708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730656AbgHTKGH (ORCPT ); Thu, 20 Aug 2020 06:06:07 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AC0D220738; Thu, 20 Aug 2020 10:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597917967; bh=DysMUwl484aGB1bJ1JQyqTW8i1SgBbgM8jezoFTjklk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=19BBsnBaWOdQbRzFnUTwZTDZeXzb8eojKIqiVRAPaW5snj8pHZL2PSWq39GmPDAUb yTblJYdZZ+xv55BdhxO4LBsMzzSxGEkKWuFQzuoMQS/dDwV9/65Rub8MzIKy2LmbSz F4W2DV+TQROQqo7uwWJAToF5lyRXKASZQXv/r++g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeffrey Mitchell , Trond Myklebust , Sasha Levin Subject: [PATCH 4.9 205/212] nfs: Fix getxattr kernel panic and memory overflow Date: Thu, 20 Aug 2020 11:22:58 +0200 Message-Id: <20200820091612.701761193@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091602.251285210@linuxfoundation.org> References: <20200820091602.251285210@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jeffrey Mitchell [ Upstream commit b4487b93545214a9db8cbf32e86411677b0cca21 ] Move the buffer size check to decode_attr_security_label() before memcpy() Only call memcpy() if the buffer is large enough Fixes: aa9c2669626c ("NFS: Client implementation of Labeled-NFS") Signed-off-by: Jeffrey Mitchell [Trond: clean up duplicate test of label->len != 0] Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/nfs4proc.c | 2 -- fs/nfs/nfs4xdr.c | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index c189722bf9c71..714457bb1440a 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -5212,8 +5212,6 @@ static int _nfs4_get_security_label(struct inode *inode, void *buf, return ret; if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) return -ENOENT; - if (buflen < label.len) - return -ERANGE; return 0; } diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index d7f8d5ce30e3e..0a7c4e30a385e 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -4163,7 +4163,11 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, goto out_overflow; if (len < NFS4_MAXLABELLEN) { if (label) { - memcpy(label->label, p, len); + if (label->len) { + if (label->len < len) + return -ERANGE; + memcpy(label->label, p, len); + } label->len = len; label->pi = pi; label->lfs = lfs; -- 2.25.1