Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933366AbdC3KBV (ORCPT ); Thu, 30 Mar 2017 06:01:21 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52752 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933346AbdC3KBS (ORCPT ); Thu, 30 Mar 2017 06:01:18 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Whitcroft , Steffen Klassert , Linus Torvalds Subject: [PATCH 4.10 03/17] xfrm_user: validate XFRM_MSG_NEWAE incoming ESN size harder Date: Thu, 30 Mar 2017 12:00:18 +0200 Message-Id: <20170330095926.447121567@linuxfoundation.org> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170330095925.918515862@linuxfoundation.org> References: <20170330095925.918515862@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1379 Lines: 39 4.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andy Whitcroft commit f843ee6dd019bcece3e74e76ad9df0155655d0df upstream. Kees Cook has pointed out that xfrm_replay_state_esn_len() is subject to wrapping issues. To ensure we are correctly ensuring that the two ESN structures are the same size compare both the overall size as reported by xfrm_replay_state_esn_len() and the internal length are the same. CVE-2017-7184 Signed-off-by: Andy Whitcroft Acked-by: Steffen Klassert Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- net/xfrm/xfrm_user.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -412,7 +412,11 @@ static inline int xfrm_replay_verify_len up = nla_data(rp); ulen = xfrm_replay_state_esn_len(up); - if (nla_len(rp) < ulen || xfrm_replay_state_esn_len(replay_esn) != ulen) + /* Check the overall length and the internal bitmap length to avoid + * potential overflow. */ + if (nla_len(rp) < ulen || + xfrm_replay_state_esn_len(replay_esn) != ulen || + replay_esn->bmp_len != up->bmp_len) return -EINVAL; if (up->replay_window > up->bmp_len * sizeof(__u32) * 8)