Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp253216rwe; Wed, 31 Aug 2022 21:18:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR7x+aVhs3/f/VXUg+uFqIUSa9PUVNXdopY+g+9VYhEFFtOVYZ3VZANg7QDiL+d9XAL4Ho0B X-Received: by 2002:a63:f962:0:b0:42b:4eaf:7c79 with SMTP id q34-20020a63f962000000b0042b4eaf7c79mr24695100pgk.463.1662005880858; Wed, 31 Aug 2022 21:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662005880; cv=none; d=google.com; s=arc-20160816; b=tkJFS46jQwIDm72QIKEXGdJrLcploRBje3hlrbWQYqJ4ZZ/WGifoDwgFcxaZb9xDBi leeP9pswj4H2WlThHy6rTR1B8iQKayiT5Kz2FwU0YcQlYByDDSQcyknL7ivnnQqZhMly HrWwoOylIJQxAf8w4ZLk6XB7q00c50R+RP8rNXHorHHhHXRsFZznGok1q2O9vBx0xDFE V4p+cJjiVjv0kb1stxeMlq2vffUuimz0gNCWafC3g0UCUbjUfu+VTunjNwtL2rczBkTg bcrI0IqpeQtH7T+reRGVCJeaZBjlJ//MWe+PdnWXAeM3P+PCxVSzHSmKTpmYQqR6C+rF 3cyw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=F9QtJAGWPoUgH7EvqJ23+lTBvakIaZr8r8lhECGqmaE=; b=NyZTL7ObfeGbkkCfK69gSte85sVXNhOaAQgdo/c4aOqhpsKcLV9F/FJhDFzL/F+qwh UBGBtzkAyfXfSW+yqrom/exFAB1reyGW7kTDVOTFPoyxPWRd3cZvGSvCvd5HoI8YJvU0 yluHBYScuNKCX3aiwcuNxYwJgm1LiOXcCtnmPk86MJxB8uHRovl2A64mzys6ii00QIB2 6JNA1znXBUWXDiYJ7z3K9C4dxCH4EOidRbZxMJaYIKyajt+5YemaMcSRhAMrEW20txL4 3a8GAvY0298p5Gby4FGkiKKDspNm1cRB7CRZ3Qpgq+OHSN5a74QvAqmXcx34KcSXbHtZ 4zkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="d64/i3z1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a1709027c0500b001731029cd79si11335064pll.208.2022.08.31.21.17.48; Wed, 31 Aug 2022 21:18:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="d64/i3z1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229813AbiIAEDW (ORCPT + 99 others); Thu, 1 Sep 2022 00:03:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbiIAEDU (ORCPT ); Thu, 1 Sep 2022 00:03:20 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D093F15C358; Wed, 31 Aug 2022 21:03:19 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id v4so15230389pgi.10; Wed, 31 Aug 2022 21:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=F9QtJAGWPoUgH7EvqJ23+lTBvakIaZr8r8lhECGqmaE=; b=d64/i3z1FUn8zNdfN8J8FhbvakCDJCdMPkNHvz0Bt1yYZv1GM8BkfI4dgZ3d7Pllik 35KUqmi061lX1aX65uVNCgs4vVXWH0eM4Ib4NecIz3pFyL1dI00eW2nc/mGSnt/xpF7J 9YIJepXyJ9TGSzDlzkh9oWxsb8Q9epItsfX1vXOLddLfbo+bEWJunkYOs8ma0N8nvySK NvmBpiA/9ZDr1qEXosJdw+fxb+TZCd0IQnQZJ8MKPQZC+KdOvK377587RyLzwvV+rMnk TJP/W6cao+iw26Xn8QrppTV7r5UmpwE0s17shi08OhsLFUpJ7DPTww3jfncA49IDEVm3 q+3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=F9QtJAGWPoUgH7EvqJ23+lTBvakIaZr8r8lhECGqmaE=; b=2X0RlmTacqRCVoOyPWGj8diadfad4xCj69p+7F5iwr4JE9HikRjb/CEJ/f5zoGrbrU YRIa/61w4MTbqdbTT1ZBYDZY093xmjQpP/aj4iW95aNo93okghRX0A9lxrKrhZksHOeg hDoFBuPkX2rw/MG2YIACjU2oKX3+3bIJPD3UkHBSPVRC1PctdFqP/RDvDhLOAmqAq6V0 WxSvnHuSvqirjpg5Rmt0hBy1z4hRHc1m7q7qjSS/5euEb3Hp4EtbEMPK1GYA+0aR7U/7 fdnm8tWqG4hANs2Pg8JZnx069UFhdu/Mb4G3ZzxWd4PAe4tkZCmHnQuNcje+qVcfiUOt MjxQ== X-Gm-Message-State: ACgBeo3UOCiSLHvZxAX+8YdD/9adzjKb1wkga1oFO76dk7J+GC4Ogo0Q GtTxuoxCWeQnh3/mLcaDqg/QsV7ZA9GaWw== X-Received: by 2002:a05:6a00:228a:b0:538:47a7:706 with SMTP id f10-20020a056a00228a00b0053847a70706mr16938794pfe.62.1662004999307; Wed, 31 Aug 2022 21:03:19 -0700 (PDT) Received: from fedora.. ([103.159.189.150]) by smtp.gmail.com with ESMTPSA id f9-20020aa79689000000b00528a097aeffsm12110215pfk.118.2022.08.31.21.03.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 21:03:18 -0700 (PDT) From: Khalid Masum To: Herbert Xu , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Cc: Steffen Klassert , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel-mentees@lists.linuxfoundation.org, Shuah Khan , syzbot+5ec9bb042ddfe9644773@syzkaller.appspotmail.com, Khalid Masum Subject: [PATCH v3] xfrm: Update ipcomp_scratches with NULL if not allocated Date: Thu, 1 Sep 2022 10:03:07 +0600 Message-Id: <20220901040307.4674-1-khalid.masum.92@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <00000000000092839d0581fd74ad@google.com> References: <00000000000092839d0581fd74ad@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 addresses 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: (1) Update ipcomp_scratches with NULL if the above mentioned allocation fails. (2) Update ipcomp_scrtches with NULL when scratches is freed Reported-by: syzbot+5ec9bb042ddfe9644773@syzkaller.appspotmail.com Tested-by: syzbot+5ec9bb042ddfe9644773@syzkaller.appspotmail.com Signed-off-by: Khalid Masum --- Changes since v2: - Set ipcomp_scratches to NULL when scratches is freed. - Update commit message. - v2 Link: https://lore.kernel.org/lkml/20220831142938.5882-1-khalid.masum.92@gmail.com/ Changes since v1: - Instead of altering usercount, update ipcomp_scratches to NULL - Update commit message. - v1 Link: https://lore.kernel.org/lkml/20220831014126.6708-1-khalid.masum.92@gmail.com/ diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c index cb40ff0ff28d..3774d07c5819 100644 --- a/net/xfrm/xfrm_ipcomp.c +++ b/net/xfrm/xfrm_ipcomp.c @@ -203,6 +203,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) @@ -215,7 +216,7 @@ static void * __percpu *ipcomp_alloc_scratches(void) scratches = alloc_percpu(void *); if (!scratches) - return NULL; + return ipcomp_scratches = NULL; ipcomp_scratches = scratches;