Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10899956ybi; Thu, 11 Jul 2019 13:02:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBiYxP0UdYI+2/SPWmGWYopr2bnznJYXy06THcMXZyM52IXCJ6pPKpbgqNKpbswmbz19hq X-Received: by 2002:a63:3112:: with SMTP id x18mr6223838pgx.385.1562875350461; Thu, 11 Jul 2019 13:02:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562875350; cv=none; d=google.com; s=arc-20160816; b=OvzRHtCQ8HxC0++UwTs81Gbj1mwkl9ln2vnY75WPNuhhb3UZngRGlIoifKMBpGql6K AqUoCK/86fRWKixapwb4aEEIbIjA8X4DMJfTfxve3TocWfQz77UA8LKiGMhnpkt1G2aw 79MSNMvOzoi+eJVWLiZoAyZgRE1HCRp8M56EDIBRH1Gg/W31gR6K9TE0dIXRZaaDDzct au5cR3CxG/Y+jt5MTgdK3w9PTdcpMzoG4E758msTl2dnc33yAqBD2CItMiR3Vz0Q4RSI 1riAzBeyKueKnXN9rCV+htLoUzXFC2VVfafoLzKgpNS6yBQRdOXKGEG4sPgy4eI3/v4x Is4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=M/KFeiCaoy+CGMT6A/kztFD97A4vmUvNnhXgwyNNtzE=; b=dcJ0lg1Ye38Xx5sXoSzh/jRMpNt9dbq/LQ6JEi9E7DmGwiXm0W9Z7Pd7IjdEo4S8Bi Mwrizgk99o2aL0FUCsl7xQxBfFFg84wSnUxms93NP9pmY+K64OAIcJVwSsgYcyEOFvdT K5ESX0RfpvhOdIRcBM1HScpn9ZXgAPcJSZZDx6jw66oVqA3T86uBfFGdaGNdFEhmpbRf 2VKyB5SKu5cwYXRIXFTVRYr2CxLKPPkaZwKmt5M81ndCkxA2AW4KihIcAxld3Jek3C1w wvwIb6addnznWcvsrrHaGQG8UnLOgM5SkRoaxcHjZKK10At1iaCoY9Z0jqiMuFXhkpaG CMBg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s6si5633730plp.229.2019.07.11.13.02.03; Thu, 11 Jul 2019 13:02:30 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729011AbfGKT7f (ORCPT + 99 others); Thu, 11 Jul 2019 15:59:35 -0400 Received: from ajax.cs.uga.edu ([128.192.4.6]:55458 "EHLO ajax.cs.uga.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726505AbfGKT7e (ORCPT ); Thu, 11 Jul 2019 15:59:34 -0400 X-Greylist: delayed 2416 seconds by postgrey-1.27 at vger.kernel.org; Thu, 11 Jul 2019 15:59:33 EDT Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (authenticated bits=0) by ajax.cs.uga.edu (8.14.4/8.14.4) with ESMTP id x6BJJFVn054162 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=OK); Thu, 11 Jul 2019 15:19:17 -0400 Received: by mail-lf1-f50.google.com with SMTP id h28so4811584lfj.5; Thu, 11 Jul 2019 12:19:17 -0700 (PDT) X-Gm-Message-State: APjAAAWxheXejtPBkf3TaMAvpn/+tA0N+iGsz0xgfiAGKc7Mri0Xr5JA R7Zu/l2iW5sxEp5lgEyrt7/Hg+Elaq5qCPaS1oc= X-Received: by 2002:ac2:418f:: with SMTP id z15mr2543647lfh.177.1562872755598; Thu, 11 Jul 2019 12:19:15 -0700 (PDT) MIME-Version: 1.0 References: <1562830033-24239-1-git-send-email-wang6495@umn.edu> In-Reply-To: From: Wenwen Wang Date: Thu, 11 Jul 2019 14:18:42 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] block/bio-integrity: fix a memory leak bug To: Ming Lei Cc: Jens Axboe , "open list:BLOCK LAYER" , open list , Wenwen Wang Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 11, 2019 at 4:22 AM Ming Lei wrote: > > On Thu, Jul 11, 2019 at 3:36 PM Wenwen Wang wrote: > > > > 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; > > + } > > This way may not be enough, and the bio payload needs to be freed. > > And you may refer to the error handling for 'IS_ERR(bip)', and bio->bi_status > needs to be set, and bio_endio() needs to be called too. Thanks for your comments! I will rework the patch. Wenwen