lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <b55f8af2-b20c-214f-90f0-9b6efcb7273c@web.de>
Date:   Sat, 20 Jun 2020 14:05:53 +0200
From:   Markus Elfring <Markus.Elfring@....de>
To:     Zheng Bin <zhengbin13@...wei.com>, linux-block@...r.kernel.org
Cc:     nbd@...er.debian.org, Navid Emamdoost <navid.emamdoost@...il.com>,
        Navid Emamdoost <emamd001@....edu>, Kangjie Lu <kjlu@....edu>,
        Stephen McCamant <mccamant@...umn.edu>,
        Qiushi Wu <wu000273@....edu>, kernel-janitors@...r.kernel.org,
        linux-kernel@...r.kernel.org, Jens Axboe <axboe@...nel.dk>,
        Josef Bacik <josef@...icpanda.com>,
        Tuomas Tynkkynen <tuomas.tynkkynen@....fi>,
        Yi Zhang <yi.zhang@...wei.com>
Subject: Re: [PATCH v2] nbd: Fix memory leak in nbd_add_socket

> If we add first socket to nbd, config->socks is malloced but
> num_connections does not update(nsock's allocation fail), the memory
> is leaked. Cause in later nbd_config_put(), will only free config->socks
> when num_connections is not 0.
>
> Let nsock's allocation first to avoid this.

I suggest to improve this change description.
Can an other wording variant be nicer?


…
> +++ b/drivers/block/nbd.c
> @@ -1037,21 +1037,22 @@  static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
>  		return -EBUSY;
>  	}
>
> +	nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL);

Please use the following code variant.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=4333a9b0b67bb4e8bcd91bdd80da80b0ec151162#n854

+	nsock = kzalloc(sizeof(*nsock), GFP_KERNEL);


…
>  	if (!socks) {
>  		sockfd_put(sock);
> +		kfree(nsock);
>  		return -ENOMEM;
>  	}

Please take another software design possibility into account.

 	if (!socks) {
-		sockfd_put(sock);
-		return -ENOMEM;
+		kfree(nsock);
+		goto put_socket;
 	}


Regards,
Markus

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ