From patchwork Thu Mar 21 09:12:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gavrilov Ilia X-Patchwork-Id: 13598532 Received: from mx0.infotecs.ru (mx0.infotecs.ru [91.244.183.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8F2A208C8; Thu, 21 Mar 2024 09:13:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.244.183.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711012384; cv=none; b=J3NBAn31D2HtOQJbFqUBkH3YUpDM38iVmijXOk1+ZjT1agsMlsveV48FhkUF9Q3C2/sxDIwPN2BbcanW6XRzViWF+m4KIDx3PkWtQVGTe6zGZsf8Y1lAG1GKnSZQ7qGZn3QrjM/o/TF7NHKFUJgDgwZxYy1lFv1/WDF8LsV00Vo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711012384; c=relaxed/simple; bh=2wY+bMrhSAAxlCEVaRSYx2ODKkeCgDYZXns76CRJxZE=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=RNUPNWVrN+UMRfx99iZl4t9rZDiP9T2IWGQZjr1N77HFFQfYuSrS0LwbuzYi/A00x3MvfL5EzbhK3RXuyxRhc/hZTVNfqhPDFn1dMfkbYQlpKMdCw4gHnKuhDfycaOZwovHbutg2IIz6gTWOoCya9ENwa/MtN/XHRr80mv3x9uY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=infotecs.ru; spf=pass smtp.mailfrom=infotecs.ru; dkim=pass (1024-bit key) header.d=infotecs.ru header.i=@infotecs.ru header.b=VlavWTCC; arc=none smtp.client-ip=91.244.183.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=infotecs.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infotecs.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=infotecs.ru header.i=@infotecs.ru header.b="VlavWTCC" Received: from mx0.infotecs-nt (localhost [127.0.0.1]) by mx0.infotecs.ru (Postfix) with ESMTP id C09DC10762CC; Thu, 21 Mar 2024 12:12:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx0.infotecs.ru C09DC10762CC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infotecs.ru; s=mx; t=1711012378; bh=2wY+bMrhSAAxlCEVaRSYx2ODKkeCgDYZXns76CRJxZE=; h=From:To:CC:Subject:Date:References:In-Reply-To:From; b=VlavWTCCJlCA3IZHSKNP4/ya2hCWQ3DrPA4CdKngZMbfBY90VyQEBEAfwuGM6HddN ePFVbTJJCPIXrfQ118qDdWCFXGtkv72+b/1N7KQ56XYgvXbprtYMuJTOYwbMbVnQdO pFjWMwBTU+lqy0qEn72UP4JwsvkxJcl85/ilJ+84= Received: from msk-exch-02.infotecs-nt (msk-exch-02.infotecs-nt [10.0.7.192]) by mx0.infotecs-nt (Postfix) with ESMTP id BCDA53196647; Thu, 21 Mar 2024 12:12:57 +0300 (MSK) From: Gavrilov Ilia To: "stable@vger.kernel.org" , Greg Kroah-Hartman CC: Michal Ostrowski , Guillaume Nault , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "lvc-project@linuxtesting.org" , "syzbot+6bdfd184eac7709e5cc9@syzkaller.appspotmail.com" Subject: [PATCH 5.15/5.10/5.4/4.19 1/1] pppoe: Fix memory leak in pppoe_sendmsg() Thread-Topic: [PATCH 5.15/5.10/5.4/4.19 1/1] pppoe: Fix memory leak in pppoe_sendmsg() Thread-Index: AQHae2/2R+13FIKrokmi6T+8fsvlew== Date: Thu, 21 Mar 2024 09:12:57 +0000 Message-ID: <20240321091256.467553-2-Ilia.Gavrilov@infotecs.ru> References: <20240321091256.467553-1-Ilia.Gavrilov@infotecs.ru> In-Reply-To: <20240321091256.467553-1-Ilia.Gavrilov@infotecs.ru> Accept-Language: ru-RU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-exclaimer-md-config: 208ac3cd-1ed4-4982-a353-bdefac89ac0a Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KLMS-Rule-ID: 5 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Status: not scanned, disabled by settings X-KLMS-AntiSpam-Interceptor-Info: not scanned X-KLMS-AntiPhishing: Clean, bases: 2024/03/21 07:23:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2024/03/21 04:23:00 #24331522 X-KLMS-AntiVirus-Status: Clean, skipped From: Gavrilov Ilia commit dc34ebd5c018b0edf47f39d11083ad8312733034 upstream. syzbot reports a memory leak in pppoe_sendmsg [1]. The problem is in the pppoe_recvmsg() function that handles errors in the wrong order. For the skb_recv_datagram() function, check the pointer to skb for NULL first, and then check the 'error' variable, because the skb_recv_datagram() function can set 'error' to -EAGAIN in a loop but return a correct pointer to socket buffer after a number of attempts, though 'error' remains set to -EAGAIN. skb_recv_datagram __skb_recv_datagram // Loop. if (err == -EAGAIN) then // go to the next loop iteration __skb_try_recv_datagram // if (skb != NULL) then return 'skb' // else if a signal is received then // return -EAGAIN Found by InfoTeCS on behalf of Linux Verification Center (linuxtesting.org) with Syzkaller. Link: https://syzkaller.appspot.com/bug?extid=6bdfd184eac7709e5cc9 [1] Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: syzbot+6bdfd184eac7709e5cc9@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=6bdfd184eac7709e5cc9 Signed-off-by: Gavrilov Ilia Reviewed-by: Guillaume Nault Link: https://lore.kernel.org/r/20240214085814.3894917-1-Ilia.Gavrilov@infotecs.ru Signed-off-by: Jakub Kicinski --- drivers/net/ppp/pppoe.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) -- 2.39.2 С уважением, Илья Гаврилов Ведущий программист Отдел разработки АО "ИнфоТеКС" в г. Санкт-Петербург 127287, г. Москва, Старый Петровско-Разумовский проезд, дом 1/23, стр. 1 T: +7 495 737-61-92 ( доб. 4921) Ф: +7 495 737-72-78 Ilia.Gavrilov@infotecs.ru www.infotecs.ru diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c index d7f50b835050..70e29e1ac4c8 100644 --- a/drivers/net/ppp/pppoe.c +++ b/drivers/net/ppp/pppoe.c @@ -983,27 +983,22 @@ static int pppoe_recvmsg(struct socket *sock, struct msghdr *m, struct sk_buff *skb; int error = 0; -if (sk->sk_state & PPPOX_BOUND) { -error = -EIO; -goto end; -} +if (sk->sk_state & PPPOX_BOUND) +return -EIO; skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, flags & MSG_DONTWAIT, &error); -if (error < 0) -goto end; +if (!skb) +return error; -if (skb) { -total_len = min_t(size_t, total_len, skb->len); -error = skb_copy_datagram_msg(skb, 0, m, total_len); -if (error == 0) { -consume_skb(skb); -return total_len; -} +total_len = min_t(size_t, total_len, skb->len); +error = skb_copy_datagram_msg(skb, 0, m, total_len); +if (error == 0) { +consume_skb(skb); +return total_len; } kfree_skb(skb); -end: return error; }