Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2279868pxb; Thu, 11 Feb 2021 08:32:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/H1aUJ+Fb8yIr65iyLQfFMB40szVPQhO44R6oRnruNK9hhhLuo71uhvi1TkoMwa0IDBd/ X-Received: by 2002:a17:906:e03:: with SMTP id l3mr9126410eji.64.1613061157272; Thu, 11 Feb 2021 08:32:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613061157; cv=none; d=google.com; s=arc-20160816; b=xOT686wFcLvmBqg/JUqdZkOLUTmoPrQGTb2lzvwm9A1nl4RP+5BJGk2PPKORYeysG/ LrHriuuiCT6wbiPXuT9208EpR5pvIUI9XF6jg0SOgt8/rOCkiWtUyl/Aw49Hnsu/H0S1 4G39L7IaInQYTHMkxalYCkhwvdA1bRgbShvZ6CNwdL+PWopz+dh9AzSAst8yuboSFxlv Lw33F5Xz5O0n7lLrLSbbWa34tCSpvAO3j8MMZOYphc2cotHtvvnIlG2kpwdpKoFUqE4C UJTtsJHZIfH51E3PjEjM39bFjNqHvgh2CD48rwtzHg9pHr5FdnbmRgl1/82kxbciqgew ivfQ== 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=r9h/yWtT2o4MmRazAWp3g02GWeNJfvJRrEH5J8xrNbk=; b=PZu+8IcdIBZMtt2ZJB6wNqr8iQoGiBWs1qiNl0VYReOmc8EW6VFtIskJQBlhR097T8 qEs6yKmWq+REHurNllpJ7mX3RwnY51ixD0o1zB6T9KxkRkbE5NaM81KQD7ar1ui0KCGX Ple/oadKDFpZBI/7X9C/yvcrBR1xi392aeuYMcU3sINGy2Fl5dH4b3Y8gx6qkjI50ctu HAGkTIRoaaGcG+X1By6ZgTH4BgqTCfiybue25sdeLx1hkzUv8V0SHbILziEkQ5m2cEDQ B9moiRUwpbTcYz9lJOSi2+nks5ZXgEUSeYmXVVVrUdlxut9E8CY2Am5EIfXWiL4uqi3z KcPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WxXc628m; 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 ke2si4140246ejc.619.2021.02.11.08.32.12; Thu, 11 Feb 2021 08:32:37 -0800 (PST) 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=WxXc628m; 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 S231494AbhBKQaP (ORCPT + 99 others); Thu, 11 Feb 2021 11:30:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:53516 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbhBKPYz (ORCPT ); Thu, 11 Feb 2021 10:24:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 822E064EC0; Thu, 11 Feb 2021 15:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613055818; bh=TCV7KUcTSr1en8/CCzAjSD+7rg3xTxSgUfFS669nnVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WxXc628mxBkKqT8JsFkPy4z6kcRFxhkCo4YA56PGebBSFxIpU5xNLHBO0yLCMGci0 OK1fDOse/0NM85vrkX1vWrLuUWk6IchpItvJdxc6X8Oz5nVcuc6TYUYVIu3wrwlwHK xz8IO3fFjPOkyBNTVSt4zqW+3nDBHVUHfpZAX/GE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+b2bf2652983d23734c5c@syzkaller.appspotmail.com, Steffen Klassert , Herbert Xu , Cong Wang , Sasha Levin Subject: [PATCH 5.10 19/54] af_key: relax availability checks for skb size calculation Date: Thu, 11 Feb 2021 16:02:03 +0100 Message-Id: <20210211150153.714973166@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210211150152.885701259@linuxfoundation.org> References: <20210211150152.885701259@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: Cong Wang [ Upstream commit afbc293add6466f8f3f0c3d944d85f53709c170f ] xfrm_probe_algs() probes kernel crypto modules and changes the availability of struct xfrm_algo_desc. But there is a small window where ealg->available and aalg->available get changed between count_ah_combs()/count_esp_combs() and dump_ah_combs()/dump_esp_combs(), in this case we may allocate a smaller skb but later put a larger amount of data and trigger the panic in skb_put(). Fix this by relaxing the checks when counting the size, that is, skipping the test of ->available. We may waste some memory for a few of sizeof(struct sadb_comb), but it is still much better than a panic. Reported-by: syzbot+b2bf2652983d23734c5c@syzkaller.appspotmail.com Cc: Steffen Klassert Cc: Herbert Xu Signed-off-by: Cong Wang Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/key/af_key.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/key/af_key.c b/net/key/af_key.c index c12dbc51ef5fe..ef9b4ac03e7b7 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -2902,7 +2902,7 @@ static int count_ah_combs(const struct xfrm_tmpl *t) break; if (!aalg->pfkey_supported) continue; - if (aalg_tmpl_set(t, aalg) && aalg->available) + if (aalg_tmpl_set(t, aalg)) sz += sizeof(struct sadb_comb); } return sz + sizeof(struct sadb_prop); @@ -2920,7 +2920,7 @@ static int count_esp_combs(const struct xfrm_tmpl *t) if (!ealg->pfkey_supported) continue; - if (!(ealg_tmpl_set(t, ealg) && ealg->available)) + if (!(ealg_tmpl_set(t, ealg))) continue; for (k = 1; ; k++) { @@ -2931,7 +2931,7 @@ static int count_esp_combs(const struct xfrm_tmpl *t) if (!aalg->pfkey_supported) continue; - if (aalg_tmpl_set(t, aalg) && aalg->available) + if (aalg_tmpl_set(t, aalg)) sz += sizeof(struct sadb_comb); } } -- 2.27.0