Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3287825ybb; Tue, 31 Mar 2020 02:09:20 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvAR22Py9dnoJ/v2M5a38sv2RRhWAv8Cga756OCz2uJNaOUTPpUNyAt8vdDJKWKlp4/3Sf4 X-Received: by 2002:aca:4142:: with SMTP id o63mr1357634oia.118.1585645760205; Tue, 31 Mar 2020 02:09:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585645760; cv=none; d=google.com; s=arc-20160816; b=Y/Z6Jjiv67dZRT40lwvs5bGy0bSX0ThUcDgNQBo272H4CJLv32P96OnGZmMGwjnIeM HZE/epccGG7p0R1tXDjI4hn3oASAVgl4TP6vswZkawm6s0IpbuVeTWbLl2WlwCWIUHGV itNdg4pc7CX9v+KEKS4ECsIz1bSxcVt/VeMRa9qiQZoXdY6odOfUyiiS8KnmZhvaVASi KU8uVp2pITsu+7+gd97tNWmmwti1c5nv8iKT5pw1WeAluIi2Q32+4nqtOWEAqp78pcuA Cr1+1IaUitu2yXA9+yQB3hWdlCeINIiMoeFQZhNLE4f0Pf1r557TMrkLUdRUNTMf5UWm mobA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mG4/hU20+TijFZ1/9epfSF9w/VUkj8Aworu6FgSZRTQ=; b=RMV73LFCqV7FmudnrpWT5YnBoNvXGtncVWwnwBssCLrTfCu6FZHhhybHiOd4wDvCSl kt9OQJXmsiom+G+vWz/0Bo2e6Cqu4leUEFMa4mU0q98d+HnS0AR++R8iysaYPtMxcVtw bStBA+4s0ev/Pt2spwcRFSy6jPQrVZVh+mn7JiDZmLdp9dc3qIQigpH1q8m8cer9gtP2 hb9IPyWIfJ3S7uRBfK91Fs4Tl6OD6RimiY43RvTSXV+HMpD/XdoC6rNFEAEQcO9hRZOb tzGnazcXlHiwwSHMLV15ThcWkDfg33uRiR/SgtD4pEEa3VJEsMU5uuDbbqtZBWez2NMY x/0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qXshFlbQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w9si8035949oti.216.2020.03.31.02.09.08; Tue, 31 Mar 2020 02:09:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qXshFlbQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731278AbgCaJHw (ORCPT + 99 others); Tue, 31 Mar 2020 05:07:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:49804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731274AbgCaJHu (ORCPT ); Tue, 31 Mar 2020 05:07:50 -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 9BE882137B; Tue, 31 Mar 2020 09:07:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585645670; bh=+2Yc5/72cHKArA4R+dzFgQDsJ7e4GYHSq8Ld72MC4zE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qXshFlbQgP+YDSO/d9YF1fMxmTaaf+oL9w9APPUOxwSdn6QYFVM9oR6hFwTUFStyP EDn59+2SwxmJ9zCofvRI4kLewKzDrRbThJ26U3mP8ui8jyvSbC6yeL2GDh5hHSmQnt 63w+3kxLWkeF5yZ5Ph9mMyxpisCem2dWtFUstRNY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Long , Steffen Klassert Subject: [PATCH 5.5 127/170] xfrm: fix uctx len check in verify_sec_ctx_len Date: Tue, 31 Mar 2020 10:59:01 +0200 Message-Id: <20200331085437.322425434@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200331085423.990189598@linuxfoundation.org> References: <20200331085423.990189598@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: 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 @@ -110,7 +110,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;