Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp639077pxv; Thu, 15 Jul 2021 12:10:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdPdT7+ikEjtfjULIdcGUd9Nd/eX9KSf2u9V/zsBy9MYa+tuxVZ01XyFst/6qavqv3H/oo X-Received: by 2002:a92:7305:: with SMTP id o5mr3638729ilc.198.1626376241264; Thu, 15 Jul 2021 12:10:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626376241; cv=none; d=google.com; s=arc-20160816; b=kqvkWWOIuKxSGv1i0VW7SNRS5riJb7oMJBaQPCOzAeKVJsR6UATY/0HtZCf5Z3hj8W mrjDb9aemZevqYrqc7T28MmbCUvNwndn6kPt5AAhoByGYXcjxBtSS6YKLFWUWTO0eW+0 HFyMjn7iIGhGSONj07feBfkdCZaqEAEXMDhUtyVQmLMcdma75WY+UxeTZ9ktos3o3Vgk pBPoHaN7FK5rsqf0F2V7MuzHe/BXMnP2moFl7ZvGgEsysViVtAa3B9BocLM9eY9DENg+ 6646JfnqnLE+AsMLKv7WFQ3Nje8rs9lvOiEgGY6Y9eze7YbHzLRG9Tugfjli75T1NMyz P4qA== 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=cYEcJ2QU78+OufSguC9YFQT6Tl6FhXa0Iv9Hz9CSpMc=; b=0gAVH66Wh3ZrjH2G392y29qtFXsnk8K2H0+ab1vErPCl4ST0rtKv/CPDw7eGS6TFpn O4q0zlHbLLREqm3YO4bI21hh7vTHK2ijbzpa2nsG8WTMjyLR0oE4iXOAcEwqh7ATo7Do eFnEj+cLuNO3Ja4ywpaZ5UEw2I4OfN0APfASkbz9xGcGJV5fSshN4rwnuyV/c7UjXcGL Sbcyvdo7LlVUpziM3ERJ6hpqE+4Dd7drkjVGSqZFEs/jjN5c0AtIrxQSFsk/NRVaKC5/ Jw0kusUjAQGr2DSrhN9dZboBLNhSRy8N0+tPZ9HgWTFvPjwyf6kcC2OSSVY2DGBeCx1p 4rNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Cyx08xFV; 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 p10si260623iov.66.2021.07.15.12.10.28; Thu, 15 Jul 2021 12:10:41 -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=Cyx08xFV; 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 S243792AbhGOTLy (ORCPT + 99 others); Thu, 15 Jul 2021 15:11:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:37234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242894AbhGOTAE (ORCPT ); Thu, 15 Jul 2021 15:00:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9E14860D07; Thu, 15 Jul 2021 18:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375431; bh=Uos9+KnPgKQ1lzahEFwmTisuEs0itSOpPl5U0et2OZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cyx08xFVi2cAbkw3bPsaA59Xpxotxyyh0a0h6DpB9uQbnz0l0BpgfPNZbPCwz7Lhs Zsd4ygsFOiZNMh9bAgFIjRJbS7jzJNNIG/7UuNZtlTTQVcuvBalGkSZ12D+FFrFou1 oPy5gxfGFhtE2bOJuTuIqxeki9rxeQQDgYHdT0rQ= 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.12 085/242] xfrm: Fix error reporting in xfrm_state_construct. Date: Thu, 15 Jul 2021 20:37:27 +0200 Message-Id: <20210715182607.977275450@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@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 5a0ef4361e43..817e714dedea 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