Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3583795ybc; Thu, 21 Nov 2019 10:26:12 -0800 (PST) X-Google-Smtp-Source: APXvYqx0mVIz1Y7WMiW7yWYu64QoHZMEJlkM6BtZFLgrYF6dUbwbGu4IukOT27IRSx5jj6bn+Ot5 X-Received: by 2002:a5d:458d:: with SMTP id p13mr12660008wrq.181.1574360772426; Thu, 21 Nov 2019 10:26:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574360772; cv=none; d=google.com; s=arc-20160816; b=atUBuiOdhh8aW+CtbQkiI2dk/ju8gADyj/BG9I7X08Zsf3xYfhcUpqNcXlYOkTUBGn tJbDxgm45sX4nzZzhxjDKxGJ+PZm3JSvRWMEi27OGRza+Axfuwv++d0w5Too8tzuNr2c qHDsj/CMMhMFf42D4BVfDvGy3h4clwEcCiLI+iWfkwEPKqRu9aVCsp825BQjG7vJpChF VELbkcEss4Z8oAJ36PLF/M6UEgMSQWyXtXMbewH776wgp4QaM23hXloOZfgGTzjHgL2p oALzGFRZq6UY1Vq3911iqWMHkBSA4B+XaFDRyS2Dx4U5LXJev4M5wsELWLJky6kaYzl/ d2CQ== 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:dkim-signature; bh=6zhjCoXgb9L0IfgOzfxkxb6svBzYxjsHedjQIL5V7AY=; b=ayrocQketZGAUUHcVO14ELOOxbmeJLTze7LQK4hREY6ukEqEUayO53v28sPK7wIkn3 ao3aMXgbly+BPeqAazxwV7bD1JG09idVR5KYBGDd41WmZqJ5AV+M8ofStJP5L1UW626a mFA5Z7Lio/uqUP/NvqDJeGZtw4GVWpj8tljgaTtjXzp1lBIcDfnwAmyeF12hSxftQQsx mVBJ0zOiiapFB68U5hTrMWJlMXFXlfhxuL4drljw/36WJ2eb5KZjgzIn9BIgkvPtWcSC ECM7JBQyoVTJSt1HgXVdX0zy4cz2TsmQSMNDN+stKwH85ntoTjw2bi785S7ACLarxers DpuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vRVFXkwJ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b31si2651542edb.302.2019.11.21.10.25.48; Thu, 21 Nov 2019 10:26:12 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vRVFXkwJ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726962AbfKUSYq (ORCPT + 99 others); Thu, 21 Nov 2019 13:24:46 -0500 Received: from mail-oi1-f196.google.com ([209.85.167.196]:43626 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbfKUSYq (ORCPT ); Thu, 21 Nov 2019 13:24:46 -0500 Received: by mail-oi1-f196.google.com with SMTP id l20so4067500oie.10; Thu, 21 Nov 2019 10:24:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6zhjCoXgb9L0IfgOzfxkxb6svBzYxjsHedjQIL5V7AY=; b=vRVFXkwJj2wwrePfM//SIRa3vMl9/Svx4A8nToAPGFIOEQqS8kSLAeYBZ/jWYg3h0R uqBgSuMfgk3qkOXzf2eCok8/gEivfrh7SYs36a7D08Oe1lOAdjrBXlLX5iOPbl24E/OD P12T3tZ4eum2QF5HLfPvhXqa6d9zdK09hmTj1uEhpcCGgwP9MO60HFEgW7FyJF+pvr75 xevi0HaxcCccm4L87QqGSQdew0wI32K/kFU3nKPOVTJdMWhEENClQ/jeGBFED/8jb56M Y5XvnsmQQEp0kFcHKBD19YeoxMnKBxnN2N3gHEX2UNqdQZlaSoj40zGkt7FEslCwLUVn 60dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6zhjCoXgb9L0IfgOzfxkxb6svBzYxjsHedjQIL5V7AY=; b=Oaphd5tfykluOFDL9rKsxFQyrEAIk8HKecMUyuc9j+2jWfh0YX34wtOhW1rpcd3Ul4 WheTcSn9Y5j313XWaobpAW+V/eslrb/aW3qHbf4asZEXl0gxyMo8DLzUoRc35HTOXw6m 9njQAKUi7/g3k3meE1mqDMJm1kgO9To/tkKQiRwDwn8GBZtN46sk+4tLiCxzsErj3LZt AmC30dp4qKTUCanNlaR+3BFrImmh3V8ehHxDTjqPDES+vl5ZxHsRVzO4MkAXi0qTaRlG Kw66xD0N0PZNsdU8+/RcH7OZGEC8JTnLNLaBFIwfLiGm8VoQqPYImRpui/Ywlg484QuV 3WEQ== X-Gm-Message-State: APjAAAXppbNKDhOQb2g7l7s194SPs4AxyPze5JTpkbIkGKHHHTbYsiMh 2zkGgy5At+2jn2gER7OVGtD9h2GFuDw7MrzkdOA= X-Received: by 2002:aca:c50f:: with SMTP id v15mr9239163oif.5.1574360685022; Thu, 21 Nov 2019 10:24:45 -0800 (PST) MIME-Version: 1.0 References: <20190923200959.29643-1-navid.emamdoost@gmail.com> In-Reply-To: <20190923200959.29643-1-navid.emamdoost@gmail.com> From: Navid Emamdoost Date: Thu, 21 Nov 2019 12:24:34 -0600 Message-ID: Subject: Re: [PATCH] nbd: prevent memory leak To: Josef Bacik , Jens Axboe , linux-block@vger.kernel.org, nbd@other.debian.org Cc: Navid Emamdoost , LKML 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 Mon, Sep 23, 2019 at 3:10 PM Navid Emamdoost wrote: > > In nbd_add_socket when krealloc succeeds, if nsock's allocation fail the > reallocted memory is leak. The correct behaviour should be assigning the > reallocted memory to config->socks right after success. > > Signed-off-by: Navid Emamdoost > --- Would you please review this patch? Thanks, > drivers/block/nbd.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c > index a8e3815295fe..8ae3bd2e7b30 100644 > --- a/drivers/block/nbd.c > +++ b/drivers/block/nbd.c > @@ -987,14 +987,15 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg, > sockfd_put(sock); > return -ENOMEM; > } > + > + config->socks = socks; > + > nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL); > if (!nsock) { > sockfd_put(sock); > return -ENOMEM; > } > > - config->socks = socks; > - > nsock->fallback_index = -1; > nsock->dead = false; > mutex_init(&nsock->tx_lock); > -- > 2.17.1 > -- Navid.