From patchwork Wed Apr 1 16:17:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 228301 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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 236EDC2D0F0 for ; Wed, 1 Apr 2020 16:55:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DCFA32063A for ; Wed, 1 Apr 2020 16:55:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585760104; bh=tmjogg9yI+Opax21DufBCCunzR9HJWzo5dAUBKQVx3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=G/Zi8ROno/8+Fa7tgdQasH9vk1FrFIjeMZu8oIKOKTe6uPVXCxa+nvJvyYWHi+3V9 Rrn6sPyANHpLWw5MXTmkjNhnmWihdZtYa/m6YufT2p+oNCaFyVmvjMmW0PeE/jubfm 3ZrkbZ3UR9o0hLMWwFMvzz62etdHJhxbt3vB6x8s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387732AbgDAQzD (ORCPT ); Wed, 1 Apr 2020 12:55:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:50624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387876AbgDAQ0M (ORCPT ); Wed, 1 Apr 2020 12:26:12 -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 B05AF20BED; Wed, 1 Apr 2020 16:26:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585758371; bh=tmjogg9yI+Opax21DufBCCunzR9HJWzo5dAUBKQVx3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E+IoVlnpcLQirIDjQ9RbuReT1tUoLeXZfP7RySgWF8yRdhLY7j7LFFYZmq2g4qgAH M6ROu0P67+3qprbJVtWqNDPclOYUjexj+cdD+3NTkfdA3TQ0xzy1tIifvXeGhWoVrA 6GgVm+kSNJ1Qe+2r78bVyYoiuAusNm56GuiDXLm8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Long , Steffen Klassert Subject: [PATCH 4.19 068/116] xfrm: fix uctx len check in verify_sec_ctx_len Date: Wed, 1 Apr 2020 18:17:24 +0200 Message-Id: <20200401161551.885439608@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200401161542.669484650@linuxfoundation.org> References: <20200401161542.669484650@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Xin Long commit 171d449a028573b2f0acdc7f31ecbb045391b320 upstream. It's not sufficient to do 'uctx->len != (sizeof(struct xfrm_user_sec_ctx) + uctx->ctx_len)' check only, as uctx->len may be greater than nla_len(rt), in which case it will cause slab-out-of-bounds when accessing uctx->ctx_str later. This patch is to fix it by return -EINVAL when uctx->len > nla_len(rt). Fixes: df71837d5024 ("[LSM-IPSec]: Security association restriction.") Signed-off-by: Xin Long Signed-off-by: Steffen Klassert Signed-off-by: Greg Kroah-Hartman --- net/xfrm/xfrm_user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -109,7 +109,8 @@ static inline int verify_sec_ctx_len(str return 0; uctx = nla_data(rt); - if (uctx->len != (sizeof(struct xfrm_user_sec_ctx) + uctx->ctx_len)) + if (uctx->len > nla_len(rt) || + uctx->len != (sizeof(struct xfrm_user_sec_ctx) + uctx->ctx_len)) return -EINVAL; return 0;