Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1966675rdb; Sun, 24 Dec 2023 09:44:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7a7ds6Y1WX6jp/am26V5auNwoffth84tLqdSQVbEMy4NzH9UidopJ2uI21xBxXwP/IhIk X-Received: by 2002:a5e:c110:0:b0:7ba:99b7:2a72 with SMTP id v16-20020a5ec110000000b007ba99b72a72mr4517726iol.20.1703439876077; Sun, 24 Dec 2023 09:44:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703439876; cv=none; d=google.com; s=arc-20160816; b=UHE0w0LvP1WJ6idjlwkJfvZdp/pUBRhXVoSPX+U3bpWlmFnP8k6UvsFHq1rur0Pn78 TLGSCUQaDlqW0B7zbd1SAc7t80r/RvG5YUlk9+66829W1v8wbxGu6+nZYY8yLgWOEo37 aVkqqmOVnbraI2rdjlZpOMO/gvZDVcqyZV05pynogVUNWEM5MZFHZ9acHlc8NvFDvkBU gAU2V1pGy59jqudnqVlCK18O0AL4J6PLeNEjj+LDHT7ua6GnWKXuGUxn6PSWfG6JMWR7 61mFZ7Z1ctS0IRfOHfyIYIyUhQxsG5uLU1AOxSfKBDCspzOojwvR9lRwjSHi4wUfHULz 412w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=/Xrwq4JtY3OSAfkwHWxb6r0DI+lLpVMm6KFhZBMoZ8E=; fh=+XbrvH0q3wgcYlqfMtz/YueuvhxnPdYwzGACHM5wF2Q=; b=slAxe3iHle8wtuBDXxsyxvqT+REL59T/u+ithm7dasQyvSziwI/KyH41ZHbWsZJnjS UIyyi9BKF/aHKWKYsMNlmKbs0r6j+FDHy0pM8qIMhnrSE0SL+ICr59FSb35ugqFnkZUq vylZhbwT5EwkV8wKShJvG5s9E5c/KsbdEelebrZ/lU5QHU2NxjXMwomH6ykf3ppHLLtX apIWrNnDDiwXQvV1uLUSb5Tazi8Il26rR04sV4OBu4afcgQFODQ5nuvwi6pDk2CakKJS O4vMaTPlOEs3Yf3MJwKtgejFNc3sQvQxh1yB7OsYy/FySAu30Hqs0nVielUDGzCkDtBf Chig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=GIbM3uEb; spf=pass (google.com: domain of linux-kernel+bounces-10780-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10780-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m66-20020a633f45000000b005ce0a6eb0cdsi1927888pga.442.2023.12.24.09.44.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 09:44:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10780-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=GIbM3uEb; spf=pass (google.com: domain of linux-kernel+bounces-10780-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10780-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B42EF281B4D for ; Sun, 24 Dec 2023 17:44:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A8B2D282; Sun, 24 Dec 2023 17:44:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="GIbM3uEb" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.smtpout.orange.fr (smtp-25.smtpout.orange.fr [80.12.242.25]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F912C8FD for ; Sun, 24 Dec 2023 17:44:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Received: from pop-os.home ([92.140.202.140]) by smtp.orange.fr with ESMTPA id HSP5rZNROiIuMHSP5rdHda; Sun, 24 Dec 2023 18:36:44 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1703439404; bh=/Xrwq4JtY3OSAfkwHWxb6r0DI+lLpVMm6KFhZBMoZ8E=; h=From:To:Cc:Subject:Date; b=GIbM3uEbJVEDTx/e7Zk17if2KvnT7AeMB2P/kINEt6QqFXlSYmYC2J/JAZC7EveMM RdZRDRoMHEow7p8vHv2GSt7Ir/nWhO7zWbK3yMQQoZ6rvzgGzySKswT/qg9HNTqatT YvTZBFKRTKIJ81OYLnBHKxE+7yE+1ms0AFGQUW5HrNfMlMzUpcZL4ecZnroamcJ+2v jIAgpeEo5ofIqLEIlZ5GVMmloHU5thouD81Bfd4kvDjMmibiJ7Ep3QHiOUuas/2DMs f+JPvv0KYD3Owvv+ukH7K0wlEcmOb12wksNrpqpytRguXZ/YxMfgTXeSpSdB5jeW8S E/J6lMWO+ZqFQ== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 24 Dec 2023 18:36:44 +0100 X-ME-IP: 92.140.202.140 From: Christophe JAILLET To: Jens Axboe , Jan Kara , Christian Brauner Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-block@vger.kernel.org Subject: [PATCH] block: Fix a memory leak in bdev_open_by_dev() Date: Sun, 24 Dec 2023 18:36:42 +0100 Message-Id: <8eaec334781e695810aaa383b55de00ca4ab1352.1703439383.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If we early exit here, 'handle' needs to be freed, or some memory leaks. Fixes: ed5cc702d311 ("block: Add config option to not allow writing to mounted devices") Signed-off-by: Christophe JAILLET --- The code could also be re-arranged to delay the memory allocation. This would be cleaner IMHO. --- block/bdev.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 6f73b02d549c..e9f1b12bd75c 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -830,8 +830,10 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, goto free_handle; /* Blocking writes requires exclusive opener */ - if (mode & BLK_OPEN_RESTRICT_WRITES && !holder) - return ERR_PTR(-EINVAL); + if (mode & BLK_OPEN_RESTRICT_WRITES && !holder) { + ret = -EINVAL; + goto free_handle; + } bdev = blkdev_get_no_open(dev); if (!bdev) { -- 2.34.1