From patchwork Mon Feb 20 06:14:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 59262 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1155335wrn; Sun, 19 Feb 2023 22:18:11 -0800 (PST) X-Google-Smtp-Source: AK7set9/X/Oxi6gQ7Twzd9a7UUX6pboGNMm9EctmQhIRQVKOAUvRbN4UeetSEkMVcQPCHogATGvA X-Received: by 2002:a17:90b:4d07:b0:230:ee59:9c92 with SMTP id mw7-20020a17090b4d0700b00230ee599c92mr2974826pjb.8.1676873891510; Sun, 19 Feb 2023 22:18:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676873891; cv=none; d=google.com; s=arc-20160816; b=ZLqfyEjbEfm/8ONHL59Re8pFPlOgrUOV6lvWfGAe2UizmEnG6FcECGFr/UhX5n/gCn FKpxvxV72Qs726z8/66UaXAJC9Y5uBxoCcbSustTWDcGd2omTK35DXDkDH3x+RAL1LDo is24snjngx/u0Bvw+x50fpoyC3+7fYJ/O+xT2E39P3iPum1p4QQBEvJRsVveelTz9F9/ Y/ezVv9mpH4PzP5wIUw2j74LQUGrQl30FsmO/qsZJ01EMkK6FqNfgT2Uz+9h9btzSQfS l8onGYFoS8T2ncmAOjATbrzFBPg/wSjCMU+Tf5NaV11d6LRjmrUUwxJKW7/PBNXpzxoB lOxQ== 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=GUsie9KImofBIVt6ox7vieWNpeJsACh8B8eIZJ6ARNk=; b=LNQBYXllkSpZHGHbVnmVjJ5YaI/y6xnXoeAqRImxmv1l0BhIagVZSCi/UCzkPUIJQS Jmi6YthmDpK7TOBuzJLwWk6Qnjx9Fm3nohFiz/5QnrYfA4epHdYuF82bKsNthHX7CjXd 5nGGnczfnFxvpY2njxfCiPGtWwpsA0MEx9r4209OdPm9yXfDO118Tga0IqloMOSZj3Bm 8E9C77tIiXFALQNWwSJ5/s1tfbfSOxxoDz4PJoPKU6mo11+fsUw6+9cGeV9YFkKPbg0n 7LBbK/t5kuAI8mKGgGVq1arOga+JDaQocEQqX12TmSWlqvGhNuI96dqvGKX6iR9sBUPh Chrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=URzNFbOI; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020a17090a3e4800b00205da45d8a5si3879274pjm.124.2023.02.19.22.17.59; Sun, 19 Feb 2023 22:18:11 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=URzNFbOI; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230051AbjBTGRB (ORCPT + 99 others); Mon, 20 Feb 2023 01:17:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229591AbjBTGQ7 (ORCPT ); Mon, 20 Feb 2023 01:16:59 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 460DCCDC4; Sun, 19 Feb 2023 22:16:55 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id CDE4660CBB; Mon, 20 Feb 2023 06:16:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16FF6C4339C; Mon, 20 Feb 2023 06:16:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676873814; bh=AkzmOYv2R3+KnWodinjT0tOoD5/NytiDQasvqL4pbCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=URzNFbOIS0pIyamvT4jTyXJ2DoQDrMCu9hbTMDfFWj27tkmX8HBu6x0Q2EV7rsR+v 31u+KC1jzNHfrqCBBALpKj7dTqG0m7d9jBLn6e2+TpPczbRMJ1DCxG3KFzi7wRkHx/ 9INKg8nR+inAukOUXX8DDzZrw+6MJ9x8GAqinVEGJClf1LJjBJ2ty9VW3b7OyAbb05 mGVNm2bVOE2qYjyEcIkON5IYKRUqHyGTr5Wi6C4fm1JFqgh7/Lxzo+gjwgOhDZlFvl 4xqwOSENCoukohBBkypjYICvwN5rMIQnCpBOJuGaRDgK3jhQQgXnV/LeVsluCKtzxp RmblhigstcELA== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Eli Cohen , Ben Hutchings , Andrew Morton , David Decotigny , linux-kernel@vger.kernel.org Subject: [PATCH net-next 01/14] lib: cpu_rmap: Avoid use after free on rmap->obj array entries Date: Sun, 19 Feb 2023 22:14:29 -0800 Message-Id: <20230220061442.403092-2-saeed@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230220061442.403092-1-saeed@kernel.org> References: <20230220061442.403092-1-saeed@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758329717958680226?= X-GMAIL-MSGID: =?utf-8?q?1758329717958680226?= From: Eli Cohen When calling irq_set_affinity_notifier() with NULL at the notify argument, it will cause freeing of the glue pointer in the corresponding array entry but will leave the pointer in the array. A subsequent call to free_irq_cpu_rmap() will try to free this entry again leading to possible use after free. Fix that by setting NULL to the array entry and checking that we have non-zero at the array entry when iterating over the array in free_irq_cpu_rmap(). Fixes: c39649c331c7 ("lib: cpu_rmap: CPU affinity reverse-mapping") CC: Ben Hutchings CC: Andrew Morton CC: David Decotigny CC: Eric Dumazet CC: linux-kernel@vger.kernel.org Signed-off-by: Eli Cohen Signed-off-by: Saeed Mahameed --- lib/cpu_rmap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/cpu_rmap.c b/lib/cpu_rmap.c index f08d9c56f712..e77f12bb3c77 100644 --- a/lib/cpu_rmap.c +++ b/lib/cpu_rmap.c @@ -232,7 +232,8 @@ void free_irq_cpu_rmap(struct cpu_rmap *rmap) for (index = 0; index < rmap->used; index++) { glue = rmap->obj[index]; - irq_set_affinity_notifier(glue->notify.irq, NULL); + if (glue) + irq_set_affinity_notifier(glue->notify.irq, NULL); } cpu_rmap_put(rmap); @@ -268,6 +269,7 @@ static void irq_cpu_rmap_release(struct kref *ref) container_of(ref, struct irq_glue, notify.kref); cpu_rmap_put(glue->rmap); + glue->rmap->obj[glue->index] = NULL; kfree(glue); } @@ -297,6 +299,7 @@ int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq) rc = irq_set_affinity_notifier(irq, &glue->notify); if (rc) { cpu_rmap_put(glue->rmap); + rmap->obj[glue->index] = NULL; kfree(glue); } return rc;