Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1353426pxb; Wed, 6 Apr 2022 16:05:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQ7xM1X5CInKtofcb141Ae+DopcsGC+gvl9DsPqkHUE7zPQHu7MUZkLc5XxyZHAiosH2s0 X-Received: by 2002:a17:906:d554:b0:6df:c373:9e5f with SMTP id cr20-20020a170906d55400b006dfc3739e5fmr10130342ejc.645.1649286305801; Wed, 06 Apr 2022 16:05:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649286305; cv=none; d=google.com; s=arc-20160816; b=RPSPPk5FqKak+OeNZOW2GnbnvxslkimVppNtBPRWXZ6L7xzasvC2KCTrGOQdzJb0iG t0sIf8X5LcrXn1CyUFf25T5q029okqxtl5avtSS1lvL3hzJZzw5fdEsGVApBOM4XPHhy NC7M/eZdyb71SPhkQJ0UzAprK6WuwpyWrorIxULZFPzKb3fB5N6H1X07PVQt/Na+HzZ9 5+WsK9LvzujjVjTT4Zxnd7z2id2/uZuwq1Pd6aNYRa+pV5pfXf3gW19lyQB/99f3O8t1 yXGwD3NhSwb0Qrbma/2NubEzgVVCQ+iy0DM0VzhhI3R7FJqEltHNDpPOMiOd79gF1hEx ptyQ== 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=CYx1gEnJeFhX0hcBMvC6AbJqvsenlxSyXFJsv+MoaHE=; b=JISoqfWSJC6IZ2+1EZQZyMpLmOFi9ai+oLW5PgAi4aNwcrB6TZB+Kh0eKhkUAyoGrg F/cDhT+o/8Rkah5LpbuTsT73EM9Avyhj+HBJZ4KgNowN1U0yFvyRSWR/pGPxz6Cp4IBt bqUWkx2wLVe33p5JGWtgCoJ2YERaTosJDreuOPxmjhv8Cy7fzaC4SgpLtenOANu5xvog JO7uHJpSjlNj81cjiWbkDe4AyQy3OIMldy6nI+HHZgpWaXoYKLoVKlGol2lJMRfSCBcr NTzhwhdd13q/PmNQCMfWFT7WRtWWRphlzdP1+7ocg1Hz3pF98Cnhhe0ktYozFXZtDC/V X7EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linbit-com.20210112.gappssmtp.com header.s=20210112 header.b=kUkwYXgt; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y14-20020a056402358e00b00418c2b5bf36si14294119edc.536.2022.04.06.16.04.31; Wed, 06 Apr 2022 16:05:05 -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=@linbit-com.20210112.gappssmtp.com header.s=20210112 header.b=kUkwYXgt; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232343AbiDFUuV (ORCPT + 99 others); Wed, 6 Apr 2022 16:50:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231468AbiDFUuH (ORCPT ); Wed, 6 Apr 2022 16:50:07 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB0013C3DD3 for ; Wed, 6 Apr 2022 12:05:28 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id n6so6158708ejc.13 for ; Wed, 06 Apr 2022 12:05:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linbit-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CYx1gEnJeFhX0hcBMvC6AbJqvsenlxSyXFJsv+MoaHE=; b=kUkwYXgtmkDRKIJ/rtwUxe+JUh+m7l723YKS7NVAlM4StAuUXqmH8xc+3BCN0MHlEz ojUrzjlZiFQQfaOPd7p38msq28KtcXjTX2T0LDE+zuKmbsIV6oiasyOfB92H7rflKIhP FtXo2rFXLOuuuqU/qujPVFyIjJfqmql0/7CkgL+Sx+7g2k6kN06saRQS2fvCF0CBeQLL BQP4oIlfAOTN069s/oiVibATpiZ6X9l85PUOlK61LmXbnx+vxR3ktqtGotc28uLJOSwH U5red2z2ZKWt2Ob2iwMGMDdsUBvYSUwuiPJHwjkIyo9HdpdVIbfguhVU7uGPxqLTKBRh yrKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CYx1gEnJeFhX0hcBMvC6AbJqvsenlxSyXFJsv+MoaHE=; b=0dtiFOGzxDF754eeyILe1Ckpi91MN5Nemc3W+ZUc8EiNwT4RhDJXob4w60mh52AFeq fFUdOrdIsBhju7m4KP1VuAIBB101B5DWl7HK7qXZt0NUTRYN2aumbN7MeTDhJvcGf0Bs GRUIDU30BWvtzqgG65KECZC+hnMhL2gBTFzdXir5Zode34aMyrePNmANwJIlLuCV/qLK UXYB/xbTMmDMWToymcxR41wQXZ1eWMun2AqZjrBkYeZl4m4pRvuZ8P6wb1XE0a6dPTlw 96hxw4G6szwPerb01okAaBKdH7t+bWi7IGbFoxEY/d2ty3mkGkf1QIwARaqKvrAcMcAA i7/A== X-Gm-Message-State: AOAM531BF1Jaxss7YDvcieYoEiCiIcgDfCsX2oRlbU+kWMRDVmTQtYrL bS+xyss8xG9nZPK4uICdS3E0Ug== X-Received: by 2002:a17:907:8a09:b0:6df:f1c6:bfc4 with SMTP id sc9-20020a1709078a0900b006dff1c6bfc4mr9926952ejc.550.1649271926937; Wed, 06 Apr 2022 12:05:26 -0700 (PDT) Received: from localhost (85-127-190-169.dsl.dynamic.surfer.at. [85.127.190.169]) by smtp.gmail.com with ESMTPSA id n27-20020a1709062bdb00b006da975173bfsm6973025ejg.170.2022.04.06.12.05.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 12:05:26 -0700 (PDT) From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?= To: Jens Axboe Cc: drbd-dev@lists.linbit.com, linux-kernel@vger.kernel.org, Lars Ellenberg , Philipp Reisner , linux-block@vger.kernel.org, Xiaomeng Tong , stable@vger.kernel.org, =?UTF-8?q?Christoph=20B=C3=B6hmwalder?= Subject: [PATCH 2/3] drbd: fix an invalid memory access caused by incorrect use of list iterator Date: Wed, 6 Apr 2022 21:04:44 +0200 Message-Id: <20220406190445.1937206-3-christoph.boehmwalder@linbit.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406190445.1937206-1-christoph.boehmwalder@linbit.com> References: <20220406190445.1937206-1-christoph.boehmwalder@linbit.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 From: Xiaomeng Tong The bug is here: idr_remove(&connection->peer_devices, vnr); If the previous for_each_connection() don't exit early (no goto hit inside the loop), the iterator 'connection' after the loop will be a bogus pointer to an invalid structure object containing the HEAD (&resource->connections). As a result, the use of 'connection' above will lead to a invalid memory access (including a possible invalid free as idr_remove could call free_layer). The original intention should have been to remove all peer_devices, but the following lines have already done the work. So just remove this line and the unneeded label, to fix this bug. Cc: stable@vger.kernel.org Fixes: c06ece6ba6f1b ("drbd: Turn connection->volumes into connection->peer_devices") Signed-off-by: Xiaomeng Tong Reviewed-by: Christoph Böhmwalder Reviewed-by: Lars Ellenberg --- drivers/block/drbd/drbd_main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c index 9676a1d214bc..d6dfa286ddb3 100644 --- a/drivers/block/drbd/drbd_main.c +++ b/drivers/block/drbd/drbd_main.c @@ -2773,12 +2773,12 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig if (init_submitter(device)) { err = ERR_NOMEM; - goto out_idr_remove_vol; + goto out_idr_remove_from_resource; } err = add_disk(disk); if (err) - goto out_idr_remove_vol; + goto out_idr_remove_from_resource; /* inherit the connection state */ device->state.conn = first_connection(resource)->cstate; @@ -2792,8 +2792,6 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig drbd_debugfs_device_add(device); return NO_ERROR; -out_idr_remove_vol: - idr_remove(&connection->peer_devices, vnr); out_idr_remove_from_resource: for_each_connection(connection, resource) { peer_device = idr_remove(&connection->peer_devices, vnr); -- 2.35.1