Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp714065pxv; Thu, 15 Jul 2021 14:13:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyE+ywmX1Pi+bfCcS4jv+00SBysa0ALm9FBfVP0x7HSlZYJN4E0IoyprH1EKQp+Q5tgKmK8 X-Received: by 2002:a17:906:1156:: with SMTP id i22mr7868505eja.167.1626383610499; Thu, 15 Jul 2021 14:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383610; cv=none; d=google.com; s=arc-20160816; b=Oj7GBy8xuWd1JxQ3VKDqNyf/ClVIai7xq32t7bTmEaDKvYxu+jp+pUlf+CVjtSiHs0 VhowYYljvbePw0r2yj8CjnM3NJwuJiW9vRYwrnKjXK2nXv1fntAnPa2Teu1DSJ+5pUCS WjrjjjVwXGNT4HjE257DHbY/2wIV/3O5h+dthr7idsA5X0yDjXfJY1UBIdjIz2yukVxw VcLXxtNbnlUFegxExFkU5c2D0xUaGxyf8ZFZfJZY7wXlJrGcqsrJum7XaCTI3IKJL7zn u1pfOWTeAbv93qAvI7e0UiPtkAb+oB7eKy3hwbYN4f9SLdmNizdAl3A16YRHCjGNWVXM U1Gg== 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=4uhG0OmXowpYyN6wl7HsO22YyGMHjfLsmyb8XdlXJ7A=; b=FdeBTEeRNs69EHjIGX72PZ2Ig+Cwdhp/97lWnr/MbhHK+1UZNpAff/Q+rDDCj6Mx4r vNGACNx8r62kJkD1ojDZL4B2T2/hUDrM9YhFm41oiroq1VNYYH1Aa3KM+W3IodzhfRhq Ku/qx1Zn/nDxM1XtK5a2XwuvJFhfQkrCJwucz9NgqzX2+6dr3HmXb/i8fez/sxndide9 HhTs5gmGa616dHVdLLcUsWEISZPuBsGG4kfBwmw1/zXdMA9K8UWgueBjcuFFIRelXHA0 CoJRd32UMPw55J82+Lk6EeeBV9xKFlF9K72Yj6ZKUzPvScDlTEL6nfaRqANJggxIz0Bc LGUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iD0nA+KF; 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 d21si9278135edx.270.2021.07.15.14.13.07; Thu, 15 Jul 2021 14:13:30 -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=iD0nA+KF; 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 S1344555AbhGOT3x (ORCPT + 99 others); Thu, 15 Jul 2021 15:29:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:45622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243956AbhGOTKQ (ORCPT ); Thu, 15 Jul 2021 15:10:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C806F613D4; Thu, 15 Jul 2021 19:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626376038; bh=NWL3vADDU6N+1LuUlaashQBGcDZ2JluWdi3H/fJzvaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iD0nA+KF4tBxURUuzFNFu5/3bFTzz2NWUf0Vl6U4+b3x/Ds60iHHxDdq/XkG/g7Vj J7vUgd8p0s3kz0iB0clv+qkpqBk0YnuKDVED0aerkL8f3PP/7JBWU29t3qNzdLTG6+ 0GYNefY9b6yLq59HhDcX9DBejg5ISVUiGvZXCxMo= 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.13 099/266] xfrm: Fix error reporting in xfrm_state_construct. Date: Thu, 15 Jul 2021 20:37:34 +0200 Message-Id: <20210715182631.527144418@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182613.933608881@linuxfoundation.org> References: <20210715182613.933608881@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 f0aecee4d539..b47d613409b7 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