* [PATCH] ISDN, Gigaset: Fix memory leak in do_disconnect_req()
@ 2010-12-26 19:59 Jesper Juhl
2010-12-28 17:42 ` Tilman Schmidt
0 siblings, 1 reply; 3+ messages in thread
From: Jesper Juhl @ 2010-12-26 19:59 UTC (permalink / raw)
To: gigaset307x-common
Cc: Tilman Schmidt, Hansjoerg Lipp, Karsten Keil, netdev,
linux-kernel
Hi,
In drivers/isdn/gigaset/capi.c::do_disconnect_req() we will leak the
memory allocated (with kmalloc) to 'b3cmsg' if the call to alloc_skb()
fails.
...
b3cmsg = kmalloc(sizeof(*b3cmsg), GFP_KERNEL);
allocation here ------^
if (!b3cmsg) {
dev_err(cs->dev, "%s: out of memory\n", __func__);
send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
return;
}
capi_cmsg_header(b3cmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
ap->nextMessageNumber++,
cmsg->adr.adrPLCI | (1 << 16));
b3cmsg->Reason_B3 = CapiProtocolErrorLayer1;
b3skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_KERNEL);
if (b3skb == NULL) {
dev_err(cs->dev, "%s: out of memory\n", __func__);
send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
return;
leak here ------^
...
This leak is easily fixed by just kfree()'ing the memory allocated to
'b3cmsg' right before we return. The following patch does that.
Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
capi.c | 1 +
1 file changed, 1 insertion(+)
compile tested only since I have no way to actually test this.
diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c
index bcc174e..658e75f 100644
--- a/drivers/isdn/gigaset/capi.c
+++ b/drivers/isdn/gigaset/capi.c
@@ -1900,6 +1900,7 @@ static void do_disconnect_req(struct gigaset_capi_ctr *iif,
if (b3skb == NULL) {
dev_err(cs->dev, "%s: out of memory\n", __func__);
send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
+ kfree(b3cmsg);
return;
}
capi_cmsg2message(b3cmsg,
--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ISDN, Gigaset: Fix memory leak in do_disconnect_req()
2010-12-26 19:59 [PATCH] ISDN, Gigaset: Fix memory leak in do_disconnect_req() Jesper Juhl
@ 2010-12-28 17:42 ` Tilman Schmidt
2010-12-31 19:21 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Tilman Schmidt @ 2010-12-28 17:42 UTC (permalink / raw)
To: Jesper Juhl
Cc: gigaset307x-common, Hansjoerg Lipp, Karsten Keil, netdev,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2022 bytes --]
Quite correct. Thanks for finding and fixing this.
Am 26.12.2010 20:59 schrieb Jesper Juhl:
> Hi,
>
> In drivers/isdn/gigaset/capi.c::do_disconnect_req() we will leak the
> memory allocated (with kmalloc) to 'b3cmsg' if the call to alloc_skb()
> fails.
>
> ...
> b3cmsg = kmalloc(sizeof(*b3cmsg), GFP_KERNEL);
> allocation here ------^
> if (!b3cmsg) {
> dev_err(cs->dev, "%s: out of memory\n", __func__);
> send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
> return;
> }
> capi_cmsg_header(b3cmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
> ap->nextMessageNumber++,
> cmsg->adr.adrPLCI | (1 << 16));
> b3cmsg->Reason_B3 = CapiProtocolErrorLayer1;
> b3skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_KERNEL);
> if (b3skb == NULL) {
> dev_err(cs->dev, "%s: out of memory\n", __func__);
> send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
> return;
> leak here ------^
> ...
>
> This leak is easily fixed by just kfree()'ing the memory allocated to
> 'b3cmsg' right before we return. The following patch does that.
>
>
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Acked-by: Tilman Schmidt <tilman@imap.cc>
> ---
> capi.c | 1 +
> 1 file changed, 1 insertion(+)
>
> compile tested only since I have no way to actually test this.
>
> diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c
> index bcc174e..658e75f 100644
> --- a/drivers/isdn/gigaset/capi.c
> +++ b/drivers/isdn/gigaset/capi.c
> @@ -1900,6 +1900,7 @@ static void do_disconnect_req(struct gigaset_capi_ctr *iif,
> if (b3skb == NULL) {
> dev_err(cs->dev, "%s: out of memory\n", __func__);
> send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
> + kfree(b3cmsg);
> return;
> }
> capi_cmsg2message(b3cmsg,
>
>
--
Tilman Schmidt E-Mail: tilman@imap.cc
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ISDN, Gigaset: Fix memory leak in do_disconnect_req()
2010-12-28 17:42 ` Tilman Schmidt
@ 2010-12-31 19:21 ` David Miller
0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2010-12-31 19:21 UTC (permalink / raw)
To: tilman; +Cc: jj, gigaset307x-common, hjlipp, isdn, netdev, linux-kernel
From: Tilman Schmidt <tilman@imap.cc>
Date: Tue, 28 Dec 2010 18:42:29 +0100
> Quite correct. Thanks for finding and fixing this.
>
> Am 26.12.2010 20:59 schrieb Jesper Juhl:
>> Hi,
>>
>> In drivers/isdn/gigaset/capi.c::do_disconnect_req() we will leak the
>> memory allocated (with kmalloc) to 'b3cmsg' if the call to alloc_skb()
>> fails.
>>
>> ...
>> b3cmsg = kmalloc(sizeof(*b3cmsg), GFP_KERNEL);
>> allocation here ------^
>> if (!b3cmsg) {
>> dev_err(cs->dev, "%s: out of memory\n", __func__);
>> send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
>> return;
>> }
>> capi_cmsg_header(b3cmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
>> ap->nextMessageNumber++,
>> cmsg->adr.adrPLCI | (1 << 16));
>> b3cmsg->Reason_B3 = CapiProtocolErrorLayer1;
>> b3skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_KERNEL);
>> if (b3skb == NULL) {
>> dev_err(cs->dev, "%s: out of memory\n", __func__);
>> send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
>> return;
>> leak here ------^
>> ...
>>
>> This leak is easily fixed by just kfree()'ing the memory allocated to
>> 'b3cmsg' right before we return. The following patch does that.
>>
>>
>> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
>
> Acked-by: Tilman Schmidt <tilman@imap.cc>
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-12-31 19:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-26 19:59 [PATCH] ISDN, Gigaset: Fix memory leak in do_disconnect_req() Jesper Juhl
2010-12-28 17:42 ` Tilman Schmidt
2010-12-31 19:21 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).