From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B32A0C4332F for ; Sun, 9 Oct 2022 22:46:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233081AbiJIWq5 (ORCPT ); Sun, 9 Oct 2022 18:46:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232427AbiJIWo6 (ORCPT ); Sun, 9 Oct 2022 18:44:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B5CD43E74; Sun, 9 Oct 2022 15:23:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B36BEB80DD2; Sun, 9 Oct 2022 22:23:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CD84C4347C; Sun, 9 Oct 2022 22:23:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665354201; bh=3ZJ2Dr8BARql+3f/+Ul44E6zF7y3fz2ppwdvpIevRAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cmENG7ajamnZ0IRfRP3f7GUASuI6OXQthXBW3dKeh8neSXZR4GTPeg0NWEQlNOeBs HTACCx3wnIrc5S01dwISdCBFPf2oRdxs2t9I5jPiVRXKZY9d5Ov3aMRtllQAj7j8T2 MsGRt/1U9G4OCgVRiH+12zXZBQ62veJQpCGhQdBqZp5kkNyp3fU4BiN7OxC/sU4jUp oSznDXS8iWpf6UbZ9GiIaQXK8JbOcuC7RJE8yOqvfIsvbybb0qExm70DV5r2HaNg9j LBB0L1e9z+caKN/DYEb1ybiPi5ST3a/4Qq81N5hyQamFBVu/uzEVLSM/QuI2ss+Bl/ iEoSfE/95AdNA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Khalid Masum , Herbert Xu , syzbot+5ec9bb042ddfe9644773@syzkaller.appspotmail.com, Steffen Klassert , Sasha Levin , davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 08/29] xfrm: Update ipcomp_scratches with NULL when freed Date: Sun, 9 Oct 2022 18:22:43 -0400 Message-Id: <20221009222304.1218873-8-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009222304.1218873-1-sashal@kernel.org> References: <20221009222304.1218873-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Khalid Masum [ Upstream commit 8a04d2fc700f717104bfb95b0f6694e448a4537f ] Currently if ipcomp_alloc_scratches() fails to allocate memory ipcomp_scratches holds obsolete address. So when we try to free the percpu scratches using ipcomp_free_scratches() it tries to vfree non existent vm area. Described below: static void * __percpu *ipcomp_alloc_scratches(void) { ... scratches = alloc_percpu(void *); if (!scratches) return NULL; ipcomp_scratches does not know about this allocation failure. Therefore holding the old obsolete address. ... } So when we free, static void ipcomp_free_scratches(void) { ... scratches = ipcomp_scratches; Assigning obsolete address from ipcomp_scratches if (!scratches) return; for_each_possible_cpu(i) vfree(*per_cpu_ptr(scratches, i)); Trying to free non existent page, causing warning: trying to vfree existent vm area. ... } Fix this breakage by updating ipcomp_scrtches with NULL when scratches is freed Suggested-by: Herbert Xu Reported-by: syzbot+5ec9bb042ddfe9644773@syzkaller.appspotmail.com Tested-by: syzbot+5ec9bb042ddfe9644773@syzkaller.appspotmail.com Signed-off-by: Khalid Masum Acked-by: Herbert Xu Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_ipcomp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c index 4d422447aadc..4fca4b6cec8b 100644 --- a/net/xfrm/xfrm_ipcomp.c +++ b/net/xfrm/xfrm_ipcomp.c @@ -212,6 +212,7 @@ static void ipcomp_free_scratches(void) vfree(*per_cpu_ptr(scratches, i)); free_percpu(scratches); + ipcomp_scratches = NULL; } static void * __percpu *ipcomp_alloc_scratches(void) -- 2.35.1