Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3378208ybp; Sun, 6 Oct 2019 10:36:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxmVsCVEwy858E3edMKO7cmKAf+VvMuD00zgEqs5zhJ/MtoinhP8gPv/DudHQ/uKF9f8e95 X-Received: by 2002:a17:906:e297:: with SMTP id gg23mr20642073ejb.47.1570383415171; Sun, 06 Oct 2019 10:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383415; cv=none; d=google.com; s=arc-20160816; b=ukrXeLN1H+VlYtFyUCQZpw3TR+yxeALYzEuaT4kT72o27n/XUZyO/Cnc5F0JJc7rOn zqOQzFtPhMvO9Wrbpo/2KtMBtzFzfWYp3hPt2r6CiXbsMkiylFQjNtbPBBaoTJd7csmV BtDdByhip1RhG94vTCpwmOBh/kX9zAgTWM5A/QEvipwggcBRVT6B5B/DPlzKn5kTdf1W /OUOn7wfMUBgGQRuS3fK/H/bbBMjyuDnY91UBDRy1cnFBYfoFa9xOTHu2mXm5phlzgT4 PiaSjDsi11fSi8HoI7lDeqhrXLbC0wFHlE8ubpyNCTgYo7Nqq5KG0/fzZ+nO3HwGhyte golw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EwbSFVXZdtPttjsIJ200llWgWjpCtGUWomjwJ8LpqX8=; b=Zkyprlw0eQJpVdwSkLSuvsOL3rxK1Pota38FarUG7TeqNiJ9zfbvL7jVD9tH1F8s5v Vni15JBR6RkBugLRHn10J+sb7jrtuoAbKBHqfCO6GSJtLbKtl9PlXOWvCyA/+J7e5OFw j/1E7nxsrKBwTCLTmTAuY2f+1LY5KD1v1CWwMiAh4kdDYonHBL20FSlHDHE78ktL7BUP 5Ht1VgibZDc1wimW6fxEgLs1yrxA0CX5ideioPTQoIDlGZZdhXz8VKgor/VtPXfrLNJG zIFSqf365lgbxaCc/nVLvhuH+9QppPW0/+bFeNrLYPVRFDpGOVn5asqdueQQS4gEQWG3 eIJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fUCmkeZc; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b26si6902032edy.108.2019.10.06.10.36.31; Sun, 06 Oct 2019 10:36:55 -0700 (PDT) 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=@kernel.org header.s=default header.b=fUCmkeZc; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729649AbfJFRcs (ORCPT + 99 others); Sun, 6 Oct 2019 13:32:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:59272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728462AbfJFRcp (ORCPT ); Sun, 6 Oct 2019 13:32:45 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ABD2121479; Sun, 6 Oct 2019 17:32:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383165; bh=1HkGendTTXSxnlp6Lr8nFsl4EaHWSMlfsJ0LFoC/HAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fUCmkeZcOv/NxMGfKtp8U2JhCQe/TAK5cW5jvcr82SH6YUYxWbj1yVOFJ8ubp3SN5 Gdy7sFAQgaeZiZ/+RvCx+FpQ8Si+lHAfaTjPYmTsZG7fPaDxcqbziAmbql24agu93a 3w/tnYmul22nevJW56t8vh+lu6gFeoTFftNrUleE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , "David S. Miller" Subject: [PATCH 4.19 088/106] nfc: fix memory leak in llcp_sock_bind() Date: Sun, 6 Oct 2019 19:21:34 +0200 Message-Id: <20191006171159.375230603@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171124.641144086@linuxfoundation.org> References: <20191006171124.641144086@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit a0c2dc1fe63e2869b74c1c7f6a81d1745c8a695d ] sysbot reported a memory leak after a bind() has failed. While we are at it, abort the operation if kmemdup() has failed. BUG: memory leak unreferenced object 0xffff888105d83ec0 (size 32): comm "syz-executor067", pid 7207, jiffies 4294956228 (age 19.430s) hex dump (first 32 bytes): 00 69 6c 65 20 72 65 61 64 00 6e 65 74 3a 5b 34 .ile read.net:[4 30 32 36 35 33 33 30 39 37 5d 00 00 00 00 00 00 026533097]...... backtrace: [<0000000036bac473>] kmemleak_alloc_recursive /./include/linux/kmemleak.h:43 [inline] [<0000000036bac473>] slab_post_alloc_hook /mm/slab.h:522 [inline] [<0000000036bac473>] slab_alloc /mm/slab.c:3319 [inline] [<0000000036bac473>] __do_kmalloc /mm/slab.c:3653 [inline] [<0000000036bac473>] __kmalloc_track_caller+0x169/0x2d0 /mm/slab.c:3670 [<000000000cd39d07>] kmemdup+0x27/0x60 /mm/util.c:120 [<000000008e57e5fc>] kmemdup /./include/linux/string.h:432 [inline] [<000000008e57e5fc>] llcp_sock_bind+0x1b3/0x230 /net/nfc/llcp_sock.c:107 [<000000009cb0b5d3>] __sys_bind+0x11c/0x140 /net/socket.c:1647 [<00000000492c3bbc>] __do_sys_bind /net/socket.c:1658 [inline] [<00000000492c3bbc>] __se_sys_bind /net/socket.c:1656 [inline] [<00000000492c3bbc>] __x64_sys_bind+0x1e/0x30 /net/socket.c:1656 [<0000000008704b2a>] do_syscall_64+0x76/0x1a0 /arch/x86/entry/common.c:296 [<000000009f4c57a4>] entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fixes: 30cc4587659e ("NFC: Move LLCP code to the NFC top level diirectory") Signed-off-by: Eric Dumazet Reported-by: syzbot Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/nfc/llcp_sock.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -119,9 +119,14 @@ static int llcp_sock_bind(struct socket llcp_sock->service_name = kmemdup(llcp_addr.service_name, llcp_sock->service_name_len, GFP_KERNEL); - + if (!llcp_sock->service_name) { + ret = -ENOMEM; + goto put_dev; + } llcp_sock->ssap = nfc_llcp_get_sdp_ssap(local, llcp_sock); if (llcp_sock->ssap == LLCP_SAP_MAX) { + kfree(llcp_sock->service_name); + llcp_sock->service_name = NULL; ret = -EADDRINUSE; goto put_dev; }