Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5550103pxb; Mon, 28 Mar 2022 14:05:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsO6cOU5FBNd6mURgW8D/JzIjCXmqRCsk+IXsFyW1qV60s9ZKH7LQThPhOXSDT6I0bh4Hq X-Received: by 2002:a05:6102:32c2:b0:325:fe:47e with SMTP id o2-20020a05610232c200b0032500fe047emr9644521vss.69.1648501514576; Mon, 28 Mar 2022 14:05:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648501514; cv=none; d=google.com; s=arc-20160816; b=FKhEYNG/Klu+6Nr+4nMrGmv0TJEXsNfgw929ljr3Vz6kTcEakRgUHJfM/ROi/n6NWW GxiorCAvSDnBi6n4sHZivcsPskRscq8FTLK2eK8rGcFaQoKYjgIU9samyC7ukrH1h1+K bXvgL0XNYCQGlwmKKsmCzVYEx4+yGoRfmqdis/i53ottcXnmAJqIsYScFCqQIFx1h+2o eBnQTq698O+zcXdqoL9msLsDrwiUQgDwj/+31qMWkhJvbf842h2DmEB6WNVuUEtVwNkL 7vN6P1XcMeRTZe5yVErExEgYzDFeokUCb0Qh3FBpbzUD23ZURGJya1rxDNTbWOKMn9G5 uxKw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Pqdm+mBE6rvDwcUiUDsdVFIdx5r1E/ZYwzEqYDEj1e0=; b=rcA8FUzICELlRiRJuiRzvrDEIp3OXP4IrmmvpBqljQni49QLJU6kWy7sLrTN0XTBBS 9BTd+hHQAizPFytiPtoR2h9EG8h7Mdlwb6kBbLfgdWOCVajX6dASzRAFMJJ8gH/TsptN BWYuyL0Bu0Yv3nwvHstZkVL7QOKVsO9C7eEhNP7tfisrUjxM0gGaAympafQJREghWGT2 nwQZUJJMAzLfREYr+MsB5ck41N7osA9+11YWgqIaPqdcjS0PBj++nI9GILUOWcLNpihP cwo+TNuRtBeu90zJvIzKLfA+Qk7l9ZLX2xF46yNVEDFY6EqkLUsrIxSGKR1X3HaIlX/b RY0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NB+PmO5b; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id v25-20020a67c899000000b00325a178ba4dsi2263059vsk.72.2022.03.28.14.05.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 14:05:14 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NB+PmO5b; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 688A56FA26; Mon, 28 Mar 2022 14:00:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239496AbiC1Iqk (ORCPT + 99 others); Mon, 28 Mar 2022 04:46:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239493AbiC1Iqi (ORCPT ); Mon, 28 Mar 2022 04:46:38 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 997D453B41; Mon, 28 Mar 2022 01:44:58 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id p26-20020a05600c1d9a00b0038ccbff1951so5149753wms.1; Mon, 28 Mar 2022 01:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Pqdm+mBE6rvDwcUiUDsdVFIdx5r1E/ZYwzEqYDEj1e0=; b=NB+PmO5b3jTtCuBHri6okNxSStdSscYcd7scQMYe+jFgLN/IzFE+S/k+w+siMZXP8U 0eJno86W9uXoIMvzol/M2MNDwdibNcN2b4FFn2m9YcSbLuppA5h7atjI47yhBw/DuZn5 rDwCyiY1dEnrzdCJJdBCtEVfFIwKQRSyjLJ6nmENR5/abqGmZiemDaSBz5RAkPZDQbAC YDdkIlBUpLasyQpvi9gqdWoN7ozOg8JQzoxag7TtvScki1DQr45K6/SYQTTX9fere8Md r1IRNilqQifjqHfyJQi13KfuAqNodpxNLeN4wA+2chspQnDeMZsBvgj6BJ5o21Z7eAhK iARg== 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:mime-version :content-transfer-encoding; bh=Pqdm+mBE6rvDwcUiUDsdVFIdx5r1E/ZYwzEqYDEj1e0=; b=0lYQvyWPisiq8pLQ91bgW4qBWOzAB+baoOY921rrwR3FQv7OopYdIbTzz1ka4HFyON U4r/rRXavbEVEeEgJ7pIqr1h6Ve8Gl1Xyv0BJ5RvbyIcEfBWUCwF/6wafR5LAktRmhJk VvIaAa8D9JNkEDnMNusHxt3p3EcZKChnInuHj9qaspVkcWRstjQeR57yH1WGtDXVCGuv 1hq9urwb02AFoskHa3lZY1LcfdbZS8IqXKEdXyXb/cX4RSrTYUwyX0dTZ2VZTKlEfynP QIy8lnaMcPXTJwDoawCW74UNv77d5uniW0s+iqFiepe1nrJp7aKL+qM3lFGrx6ppHTRW ljUg== X-Gm-Message-State: AOAM530RLzG+TiaZmRnhaLM9k2zy9oi6/a5rqLScwgx5nh7rUFOiwhxJ 378GfHkowyVOIQvChKaQscU= X-Received: by 2002:a7b:c186:0:b0:38c:75ea:4903 with SMTP id y6-20020a7bc186000000b0038c75ea4903mr24461122wmi.176.1648457097197; Mon, 28 Mar 2022 01:44:57 -0700 (PDT) Received: from localhost.localdomain (host-95-249-145-232.retail.telecomitalia.it. [95.249.145.232]) by smtp.gmail.com with ESMTPSA id o5-20020a5d4a85000000b00205a8bb9c0dsm10493303wrq.90.2022.03.28.01.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 01:44:56 -0700 (PDT) From: "Fabio M. De Francesco" To: axboe@kernel.dk, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Cc: "Fabio M. De Francesco" , syzbot+f08c77040fa163a75a46@syzkaller.appspotmail.com Subject: [PATCH] scsi: sd: Jump to out_free_index if device_add{,_disk}() fail Date: Mon, 28 Mar 2022 10:44:52 +0200 Message-Id: <20220328084452.11479-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 Currently, if device_add() or device_add_disk() fail, the code jumps to the "out" label. Doing so we get a memory leak as Syzbot reports.[1] Fix this bug by jumping to the "out_free_index" label. [1] https://groups.google.com/g/syzkaller-bugs/c/BvuqG6YGb6I Reported-and-tested-by: syzbot+f08c77040fa163a75a46@syzkaller.appspotmail.com Fixes: 2a7a891f4c40 ("scsi: sd: Add error handling support for add_disk()") Fixes: 265dfe8ebbab ("scsi: sd: Free scsi_disk device via put_device()") Signed-off-by: Fabio M. De Francesco --- drivers/scsi/sd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index a390679cf458..61fcf653ef5a 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3434,7 +3434,7 @@ static int sd_probe(struct device *dev) error = device_add(&sdkp->disk_dev); if (error) { put_device(&sdkp->disk_dev); - goto out; + goto out_free_index; } dev_set_drvdata(dev, sdkp); @@ -3475,7 +3475,7 @@ static int sd_probe(struct device *dev) error = device_add_disk(dev, gd, NULL); if (error) { put_device(&sdkp->disk_dev); - goto out; + goto out_free_index; } if (sdkp->capacity) -- 2.34.1