Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp1961957imc; Fri, 22 Feb 2019 14:46:14 -0800 (PST) X-Google-Smtp-Source: AHgI3IZlbjiWthaUX2A/UNNtINqLfR0X8hJZ0eVLJme9xbega3lTbiSDeC1PSrxdw3cabOjFexef X-Received: by 2002:a62:1ace:: with SMTP id a197mr6625533pfa.78.1550875574749; Fri, 22 Feb 2019 14:46:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550875574; cv=none; d=google.com; s=arc-20160816; b=fI5Eknm09QSKORwxIsPhQF/vSiWA15SBrisryAEiMCZtaDGdakHmB6moHhBEnpBIV3 R3EwxF/1gD++VMte1E+wdt2f/yWix4MbNC1c3+ObManoYISOPJqH9YfSpBGXumdsLIq/ UMqtPNDwNX6UOSyUoRUrYEXfRZB+fnO4FeC9dzNCxxAIS/19knEoQ1thImzWT3bgUmqk A/zdHbBrebBFn6RNCin5zqa3eyeSJQo0dJZfpxZbMny8xjfF4gWx7u9paBfGCE2mEJ/V lqvx/9gVCICgKJXceu1+gxFpzwdDCdPsDnybgqeW6i1PoNwcGfE+EVYhnLeBFW+VQxW5 Kzzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=HM3z1h6Y/c8V9hSCjXLDcfbwF24eivSumdL4qxgvxUc=; b=jQvAv7qsOURBzMPoLDrDN6EVur8hI6miRipfPp3PODcAYDYpIvKHJogO60p/3LfAho 6/nv4lX0ANoZJ/jFBFbFvmw+TLwkfujCLB+O2AXhW0TDSc9PwOAhZ+hhkTCOh/0fJk2Z 94HjKAGvTtzWIyCRc6GOM39eFbbfI5lIgQJCnhN+WirjO9NU/dFRnfFEqLEfR0URX45y 73sO/XejzK+MGnUpiNgLGnTFVLOZaeWF0EdzF8LeZaHBY/0WiC+o4UFrJVwK/kO3bLBL GgB34ip7cO3VgFF/xkWy7OwVS2tYlB1RN/aRt9PHaCBiQF8tE56wjLp1OEJXMvKfmstw j38Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5si2385708pfi.60.2019.02.22.14.45.59; Fri, 22 Feb 2019 14:46:14 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726434AbfBVWpW (ORCPT + 99 others); Fri, 22 Feb 2019 17:45:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52732 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726080AbfBVWpW (ORCPT ); Fri, 22 Feb 2019 17:45:22 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 25E0ACAA72; Fri, 22 Feb 2019 22:45:22 +0000 (UTC) Received: from localhost (unknown [10.18.25.174]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBF4D5D9CA; Fri, 22 Feb 2019 22:45:19 +0000 (UTC) Date: Fri, 22 Feb 2019 17:45:18 -0500 From: Mike Snitzer To: sultan@kerneltoast.com Cc: dm-devel@redhat.com, Alasdair Kergon , linux-kernel@vger.kernel.org Subject: Re: dm crypt: fix memory leak in dm_crypt_integrity_io_alloc() error path Message-ID: <20190222224518.GA11359@redhat.com> References: <20190216210022.29483-1-sultan@kerneltoast.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190216210022.29483-1-sultan@kerneltoast.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 22 Feb 2019 22:45:22 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 16 2019 at 4:00pm -0500, sultan@kerneltoast.com wrote: > From: Sultan Alsawaf > > dm_crypt_integrity_io_alloc() allocates space for an integrity payload but > doesn't free it in the error path, leaking memory. Add a bio_integrity_free() > invocation upon error to fix the memory leak. > > Signed-off-by: Sultan Alsawaf > --- > drivers/md/dm-crypt.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c > index dd538e6b2..f731e1fe0 100644 > --- a/drivers/md/dm-crypt.c > +++ b/drivers/md/dm-crypt.c > @@ -939,8 +939,10 @@ static int dm_crypt_integrity_io_alloc(struct dm_crypt_io *io, struct bio *bio) > > ret = bio_integrity_add_page(bio, virt_to_page(io->integrity_metadata), > tag_len, offset_in_page(io->integrity_metadata)); > - if (unlikely(ret != tag_len)) > + if (unlikely(ret != tag_len)) { > + bio_integrity_free(bio); > return -ENOMEM; > + } > > return 0; > } Since commit 7c20f11680a4 bio_integrity_free() is no longer and exported symbol. But that aside, this dm-crypt clone bio's endio will clean up the bip once -ENOMEM return starts to make its way out via crypt_alloc_buffer()'s bio_put(). Mike