Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10161176ybi; Thu, 11 Jul 2019 00:37:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWU9Ht5uiZwgos8JN3VJbb/tW4ixroD+eUljixCsDbsFdEjRwxoTXaYxA4N9QreXZIzkDI X-Received: by 2002:a17:902:b603:: with SMTP id b3mr3076357pls.9.1562830635557; Thu, 11 Jul 2019 00:37:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562830635; cv=none; d=google.com; s=arc-20160816; b=Yfpd7Uw8EHR/ju6eKPYX9YbAZcJalKCSmmh+MybFabM/t7ys5OwBrZtgM2fVw1v/Wk 3HSK3ALkQ7F7ExPKfV0WuP5/4DBCG3kp97+gKWWMNNA6bgwAQi28ALsz3aFeISADlO+c luQdYDKP2X48sZ8g9TeLgKOu2fPcKuJzX1rh7JWATwQY+ErhdgdFAci//RowoVere3yi 2cFk3/c3RHVbqhNcgfjj0pWGlw76pFAotbV/X23eEBCe9GMqjtdDfsZ0AxAeL4dGe6oC eYpXBVF7ej+heLhQydMxiWlwXhi2p59Fup6nXlY6Suak7jqnG+1qusVwHe8SMFrt84zI xqBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=X6Z4l/JCt0vrAzTI2h9ZAgt6VJx8sy/c7Jhl6qpnxtE=; b=M1qJGiu9zx4tOmXHogxoo6nO7VtIqBUxosXD4eLomPKRlI/l2Z9Q04XPIcEdDpjVQY a6gBXDUGFgTMyPco/nLrEUmgp0SvoPVdXDbu+kSAh8Pc5111ybNB+4LiumPFD9rDqHLo vEEx9cQnsMRdYqP8CfF/unoVBMhi86LbSXZs3CTmecGMn2OIHoxNfUHkR4dkCMcKBr9K dQgpkqP+uARCTyu1EoyalXl62FgSC1Bj45UGMRtNpHyc55IF3UFZ2FtEmLbpkLTicsas 77YLYgWRXRwKW6Bj5EKDiftxY2FP12oAx/kE68vy55KCEXIv5CsbIKbiTDtwIH1OuKTC EwMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=B5cgJ620; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u3si4263300plz.201.2019.07.11.00.36.59; Thu, 11 Jul 2019 00:37:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=B5cgJ620; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728139AbfGKHgd (ORCPT + 99 others); Thu, 11 Jul 2019 03:36:33 -0400 Received: from mta-p7.oit.umn.edu ([134.84.196.207]:32928 "EHLO mta-p7.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725963AbfGKHgc (ORCPT ); Thu, 11 Jul 2019 03:36:32 -0400 X-Greylist: delayed 545 seconds by postgrey-1.27 at vger.kernel.org; Thu, 11 Jul 2019 03:36:32 EDT Received: from localhost (unknown [127.0.0.1]) by mta-p7.oit.umn.edu (Postfix) with ESMTP id 508BEC01 for ; Thu, 11 Jul 2019 07:27:26 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p7.oit.umn.edu ([127.0.0.1]) by localhost (mta-p7.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6Ldinn9E4n1y for ; Thu, 11 Jul 2019 02:27:26 -0500 (CDT) Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p7.oit.umn.edu (Postfix) with ESMTPS id 2A4D16F6 for ; Thu, 11 Jul 2019 02:27:26 -0500 (CDT) Received: by mail-io1-f71.google.com with SMTP id s83so5803922iod.13 for ; Thu, 11 Jul 2019 00:27:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id; bh=X6Z4l/JCt0vrAzTI2h9ZAgt6VJx8sy/c7Jhl6qpnxtE=; b=B5cgJ620d3ZMpNa1G6S58M+oUNja9lxJD/3DbqQQ93KJ3PcWiMcxlTG/amKvq3j2Gp pRiE1AmRc1JY8Sjx8DCP5bM/9XpaeHEGWPxHk7PvLqdHZk3+imC4zK0kCBPofu2LfFDe PoYANvx2C2YDJKnkW3Z7e+OYbxsvOFy9fvf13eqIwF4jDepHNoGR26LtkC+UPVwCl9YU gCL3pzHzExUWWSGYbBgUL6EnNFOad7g+KiOA4rYVK7m9inz8KLIwzG9E8x7V3NLyrrrv NMNb7wFw5QgMx1cafyxNzCOcn9LfBdAMiVYSKNK7PbQOULlKxcTqIoFq3FYebPKshazh oCwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=X6Z4l/JCt0vrAzTI2h9ZAgt6VJx8sy/c7Jhl6qpnxtE=; b=TxZDtFYHHwdxJ56rwGvr93SXbhXixDcOrmx9A3EiEplsiFlzY0Vkx3qz5Ne26jV4yr csXYXyxa8dW1znJe8IllzQwc0mK7vnpt/ZEQHfjb3sNQoQ+85avIjaGjujYjjUwujTlr VgkDtzOAXBhUSKrtlFiLhhiSM23XRW8Aetb7L8z3MX8uEFHY5ra8QYM1u1zu8Uidu4pc SYPHTWvTaganMCYBYhwU92OBwJalcL4YynhPG0TjnBt2v+VpoYdxkqwiED0bHCkeK7us J7jIrMH5YWhSeKlf3jOFusMNqaPvo+ofH2cqpBc4vwfTGjJc4i7zisRbU4ejV95yRl4q 8ybQ== X-Gm-Message-State: APjAAAU8FjiimiRFlQ5whaQ5Z/Phv0K1oIImSt4SyUOthyHfRFKfc63b HUcasT00/y1EtpMotN5wgug/Lnt1a73gArCGmeqUToffKQRkZoKHH8iBG7oeobBgs+zb4rMVQ5a 6v9U6kpgx39bT6H1R8YlrAe3nIPpK X-Received: by 2002:a5d:8253:: with SMTP id n19mr2771291ioo.80.1562830045521; Thu, 11 Jul 2019 00:27:25 -0700 (PDT) X-Received: by 2002:a5d:8253:: with SMTP id n19mr2771269ioo.80.1562830045327; Thu, 11 Jul 2019 00:27:25 -0700 (PDT) Received: from cs-u-cslp16.dtc.umn.edu (cs-u-cslp16.cs.umn.edu. [128.101.106.40]) by smtp.gmail.com with ESMTPSA id i23sm3303359ioj.24.2019.07.11.00.27.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Jul 2019 00:27:24 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Jens Axboe , linux-block@vger.kernel.org (open list:BLOCK LAYER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] block/bio-integrity: fix a memory leak bug Date: Thu, 11 Jul 2019 02:27:12 -0500 Message-Id: <1562830033-24239-1-git-send-email-wang6495@umn.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wenwen Wang In bio_integrity_prep(), a kernel buffer is allocated through kmalloc() to hold integrity metadata. Later on, the buffer will be attached to the bio structure through bio_integrity_add_page(), which returns the number of bytes of integrity metadata attached. Due to unexpected situations, bio_integrity_add_page() may return 0. As a result, bio_integrity_prep() needs to be terminated with 'false' returned to indicate this error. However, the allocated kernel buffer is not freed on this execution path, leading to a memory leak. To fix this issue, free the allocated buffer before returning from bio_integrity_prep(). Signed-off-by: Wenwen Wang --- block/bio-integrity.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 4db6208..bfae10c 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -276,8 +276,10 @@ bool bio_integrity_prep(struct bio *bio) ret = bio_integrity_add_page(bio, virt_to_page(buf), bytes, offset); - if (ret == 0) + if (ret == 0) { + kfree(buf); return false; + } if (ret < bytes) break; -- 2.7.4