Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp627295pxv; Thu, 15 Jul 2021 11:54:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjFLoUMBffLcWfHXDD95ynIS2IJLUn+wSy4xixpzP3I8hsv/+yxIBwHe9AHcUHlG7KK/TX X-Received: by 2002:a05:6638:1316:: with SMTP id r22mr5355792jad.89.1626375273382; Thu, 15 Jul 2021 11:54:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375273; cv=none; d=google.com; s=arc-20160816; b=l6WK3SHtdWwVifIbDcvYDRROYsmXd8bFjmD1ywohFFGKv88JSNnovgwdi1FCh2spIJ 1N6/xnBZWEL9S4DCDf1WrIW9VOUWsg7kpW05b9pis64iJXe8KEG0b6BxDhCc+7IDb85T GHbSlNi/npy4nsaolRiiFySKNgrkKp3KiVDhVa35js/4evvN0m784rI+IGislm2cxTby i3rBYkqMKsEun4vsFt00swcwFo4no6RjSFkAoWB+fxyjEro60pMr66+eKQBtmFQFGigR BBNIOkZizIw12zhvu/NvPUIXMywmHHwBt//GsPZUXT03GJMxwK0vXYzPLuegso7fJAO+ HXJQ== 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=GC565U5NXnaWRoMtnfo1Io6Xf9VXEH8pxAqZLpjVv5E=; b=JDWBoSSUntSxqQZS42YDaF5oF/SNXvLLwgulv/OqzYhHa5c1dUsRJTe8/A+UZi6X+i YzrEvug2MgGZ2pPDkscwQr+qdkoFSDTLcNz/imdCJXtBnzCbHjbz0+ur80IQAaeCxdFM +7tF4zicO76T5nTicmtMoF5zVo+u/poBx0/jxCdVWaqB+0BmeIDjvyzdCTgRLH7pjTKz 30sjhxdpFnDLOGsXMzTntib+qnIzqPFq7EIghPOaDEonuP5bwaxeBH8Co7Lq+hi6ugqM zV9dPTVSA5uJwW4dU6wxQXkV56jBpcpJDSJHMvAgIqkCjkuSV0eM6eBLN+T2x9N3J3v8 tKfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uGXAhZtY; 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 y1si8537332jab.59.2021.07.15.11.54.21; Thu, 15 Jul 2021 11:54:33 -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=uGXAhZtY; 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 S234129AbhGOS4o (ORCPT + 99 others); Thu, 15 Jul 2021 14:56:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:54550 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239126AbhGOSvW (ORCPT ); Thu, 15 Jul 2021 14:51:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C8912613E3; Thu, 15 Jul 2021 18:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626374908; bh=jFSMofy9TP1jCzwJh7+cw0YgBnKGkyqc4awKL9lg4B0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uGXAhZtYHZ8mWyV0BnmQm4VcHhD+5ifB47UrjqOJQ6jxw0lNNHUhPa38rP85aWhtB AEmikKUoHEEwKz/88PVzn5dvK1M6diYOwBxzSxXpzNoxhNJb0q6cyrDklWGGLFlkdL sy/S+lyGTTC/hn/HsPsmDwnWd408hawmhawIQ8H4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tobias Brunner , Steffen Klassert , Sasha Levin Subject: [PATCH 5.10 077/215] xfrm: Fix error reporting in xfrm_state_construct. Date: Thu, 15 Jul 2021 20:37:29 +0200 Message-Id: <20210715182613.084944872@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182558.381078833@linuxfoundation.org> References: <20210715182558.381078833@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: Steffen Klassert [ Upstream commit 6fd06963fa74197103cdbb4b494763127b3f2f34 ] When memory allocation for XFRMA_ENCAP or XFRMA_COADDR fails, the error will not be reported because the -ENOMEM assignment to the err variable is overwritten before. Fix this by moving these two in front of the function so that memory allocation failures will be reported. Reported-by: Tobias Brunner Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_user.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index d0c32a8fcc4a..45f86a97eaf2 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -580,6 +580,20 @@ static struct xfrm_state *xfrm_state_construct(struct net *net, copy_from_user_state(x, p); + if (attrs[XFRMA_ENCAP]) { + x->encap = kmemdup(nla_data(attrs[XFRMA_ENCAP]), + sizeof(*x->encap), GFP_KERNEL); + if (x->encap == NULL) + goto error; + } + + if (attrs[XFRMA_COADDR]) { + x->coaddr = kmemdup(nla_data(attrs[XFRMA_COADDR]), + sizeof(*x->coaddr), GFP_KERNEL); + if (x->coaddr == NULL) + goto error; + } + if (attrs[XFRMA_SA_EXTRA_FLAGS]) x->props.extra_flags = nla_get_u32(attrs[XFRMA_SA_EXTRA_FLAGS]); @@ -600,23 +614,9 @@ static struct xfrm_state *xfrm_state_construct(struct net *net, attrs[XFRMA_ALG_COMP]))) goto error; - if (attrs[XFRMA_ENCAP]) { - x->encap = kmemdup(nla_data(attrs[XFRMA_ENCAP]), - sizeof(*x->encap), GFP_KERNEL); - if (x->encap == NULL) - goto error; - } - if (attrs[XFRMA_TFCPAD]) x->tfcpad = nla_get_u32(attrs[XFRMA_TFCPAD]); - if (attrs[XFRMA_COADDR]) { - x->coaddr = kmemdup(nla_data(attrs[XFRMA_COADDR]), - sizeof(*x->coaddr), GFP_KERNEL); - if (x->coaddr == NULL) - goto error; - } - xfrm_mark_get(attrs, &x->mark); xfrm_smark_init(attrs, &x->props.smark); -- 2.30.2