Received: by 2002:a05:6a10:3150:0:0:0:0 with SMTP id m16csp3145876pxc; Tue, 12 Apr 2022 14:52:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKq6KyDLmZomijUfPmgj8f9qhF5I/JXqK7epG1ZkhEryQOFKWJkdnq8xtt/eFRdFN9/jP3 X-Received: by 2002:a65:6a07:0:b0:39d:8c35:426b with SMTP id m7-20020a656a07000000b0039d8c35426bmr5298716pgu.171.1649800356895; Tue, 12 Apr 2022 14:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649800356; cv=none; d=google.com; s=arc-20160816; b=yMGxrMgP8ITCcTQm9vfentwTmCQ+E5MmmXLO5Q9sd1XkWXPwUbxdX3fhylp1GDAMEV w7ydiwuugdfNRBMH5spaxR9pTaultdL22VQ6Ven2PKd1LKquzVV/H9W0yA3IwcXmvemf 5f1IaOnoqUi687RT3vji9gnekfKcMm++ano6xSfw6JHSiH821EWgiKV1NAETM/uIq5oa ysPNxzcuLpDWWDKyN4Uh38bvlSMO2SqmoGu3ablWCzqMX7fLrnlzPP6z1grDUZ16To9S Fogt5QQ2Hy+X8rASzfNYUKA7BJGrKQpQmr63Seiu11T3TO4S6L8hEHLyVUAqwQAj4m/K otaw== 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=OO+hGI851EsTGXs4HXpyNs+EhtoCULL+8KywWBSi7BE=; b=t0qiLg5qWAoODIcXv0JCNceqVYkMOCwqAaPc+5on5TgkAICh1Ul03iTiVa3l50vLeZ ZzBWWcdWH+6lOpRFUkMDzutdP7TzHp7yzETkTkVh7MTy7myjdNN79Bs/m8u4CyIKZAss tTgw/TldN93ljIAxx94DY/SkVjQ1sx7f0k2FbFLG/7wswapNZ+1TLWh6F42883pRW5l7 NRAMszghQwMI+9wmKs/e0jnYqPF9y+P0rB1M2F3NU4nEcEarfET/dO95nPR69aeramp0 Pv8h9cDxynsc5vON4K7dJbHKFzm4KRau6JJA++3J+EoZlW0Rpy2xlFMMU/N5hndlfy3F Cw9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0SEp48sk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h8-20020a628308000000b00505769e7c34si12059762pfe.367.2022.04.12.14.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 14:52:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0SEp48sk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0F28115AACB; Tue, 12 Apr 2022 13:54:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380452AbiDLIWO (ORCPT + 99 others); Tue, 12 Apr 2022 04:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353858AbiDLHZ4 (ORCPT ); Tue, 12 Apr 2022 03:25:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D44CFE013; Tue, 12 Apr 2022 00:04:58 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 71A3360B2E; Tue, 12 Apr 2022 07:04:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8722FC385A6; Tue, 12 Apr 2022 07:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649747097; bh=WNmc1U1T4VK9eOAieNnS6QYXaRY1fquINd9tlCqMHNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0SEp48skaw6qBI4sQ1YCRfeW6oC9IVq9zM0fSsmLH6LzNQQH5no6jyTaEH/myKSNy EQ+ovNEmUCvH9EnlyfwRfASCULyYGdTmkic5QLqJaFWFmEGawt2kuPuaqQdyCPLH/f WfuB93zey1An1vX/qs7PcSqKFuxr2ssetMIVlwu8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaomeng Tong , =?UTF-8?q?Christoph=20B=C3=B6hmwalder?= , Lars Ellenberg , Jens Axboe Subject: [PATCH 5.16 240/285] drbd: fix an invalid memory access caused by incorrect use of list iterator Date: Tue, 12 Apr 2022 08:31:37 +0200 Message-Id: <20220412062950.589685667@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412062943.670770901@linuxfoundation.org> References: <20220412062943.670770901@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 commit ae4d37b5df749926891583d42a6801b5da11e3c1 upstream. 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 Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/drbd/drbd_main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/drivers/block/drbd/drbd_main.c +++ b/drivers/block/drbd/drbd_main.c @@ -2791,12 +2791,12 @@ enum drbd_ret_code drbd_create_device(st 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; @@ -2810,8 +2810,6 @@ enum drbd_ret_code drbd_create_device(st 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);