Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2266633pxb; Thu, 11 Feb 2021 08:16:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJYFpsA60+N5ZUBQ1dUiR1mtQ2EnMNSgdLzcCHZAkOU2GXARquXn8GKh87BJmfgxytCU0t X-Received: by 2002:a05:6402:17aa:: with SMTP id j10mr9240090edy.184.1613060182476; Thu, 11 Feb 2021 08:16:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613060182; cv=none; d=google.com; s=arc-20160816; b=LhPmn0TJtK4yMHK8f6HNg3WIl/B9Pdt1imK0jJsDoiFy+imGs9QfOlMVQC3oNo9NCh i7TtA/dFuce4jCrChT7p+zBwb7VJTg5sF4E+Zct0w57O/uzDu5e7scCRunUFXzZdluzl t75HgCQUstSrDzRXEMneqAC7eLCW71yf9DAQ8Bt2pet3ZRLntyQNYWI8GxYagTTc0/AA B/OAjYJ5Y9UN9j4+ZSSb7+6kUm0IHapjQhl2ZVOjreQ2ngVyR7DjcoyZmpush0FvIvHJ +taqWBendHJ0hKv7KKjQ16pGdVhT+vzxgtped3PmzJPNXHlbyyYwfm5bdqfvupukRpPo dWsA== 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=BtygLfpsxizoMCjtjKUzh12vCJ6dEFM5Bveq9iHv4+Y=; b=IZ2XlCxDbYCsOLdil0NS2TgbHiGE5LO3N6UrAw5h7dEsX/EBNy2aV600zNK6QDcION 43TfVpfc4JC8aHbfJ9loql0g1NBWtXU5JcWIoyF4fsRWbCoPPjZvwPzps0XmKFXWV58k bw/Ev0LvtHE6gWCAy6CnisDsCi67M0mioL/nODYHQDRYR+f7LN0P/1X5b8B/ZU72P622 Nl8qSQ5dLjzvmnnx8X1kbRc89avkFcwi8PQ1ZfDAmg6HCLa7Cmr2koXrEVvHJ2xa24tr PDx4aIM1jeSt1ionQboSJ27DtS9X72HrSix2kq5bYIJl4bRyPfbNrQpMcrkpiOwSoOP4 oGcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ISDQ8ZBL; 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 y11si4195204ejk.293.2021.02.11.08.15.50; Thu, 11 Feb 2021 08:16:22 -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=ISDQ8ZBL; 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 S231651AbhBKQPM (ORCPT + 99 others); Thu, 11 Feb 2021 11:15:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:53524 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230436AbhBKPWi (ORCPT ); Thu, 11 Feb 2021 10:22:38 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1B2D764F38; Thu, 11 Feb 2021 15:07:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613056043; bh=Gyko2fH262bh7ohxuvJOx5kBhTezFJQX5eqq9T8pDbo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ISDQ8ZBLr3S6lWnDEp8UkG9Y2bQXxhvjFrN78AiTNVzBOIcj1lNP/p/Qp0ShvYzJJ Crr7EK8Xuzfpt2CC2Mne8AlR9jxfbGjQpes3h8/LtcWjWl5WFWbmAnKCCdUuoePkN5 0O1RUcH1tQWb5qg3BlHq3VGEmcwK0IHE93kg2rr4= 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 4.19 06/24] af_key: relax availability checks for skb size calculation Date: Thu, 11 Feb 2021 16:02:40 +0100 Message-Id: <20210211150148.026903055@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210211150147.743660073@linuxfoundation.org> References: <20210211150147.743660073@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 e340e97224c3a..c7d5a6015389b 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -2908,7 +2908,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); @@ -2926,7 +2926,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++) { @@ -2937,7 +2937,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