Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4324679pxj; Tue, 8 Jun 2021 11:31:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyisGeYlBBgt6lbolNxk3giFbHRRxr0UGMfeXn+VK+98W3d2Xl6N9rUdisY+cm/9+4fEnYD X-Received: by 2002:aa7:d482:: with SMTP id b2mr27236697edr.45.1623177099424; Tue, 08 Jun 2021 11:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623177099; cv=none; d=google.com; s=arc-20160816; b=KpnMg1Xk8j7WramLEhSNajQ/lplTMwIFFtRR3Kq3/SavM6Ivr4G/wr5ym+DVsazt3r G4VH3R8SLyE3gvHPXFqD9pfhMJK/AjXW95xN/Rtxov6V9PsXeENN1PHwj1Sp2RYWLJdf Rv6eYbFhn/Y4OioHAZrKUmxNH0os4RaLRHik0/ak1cDmXKvS02xLESkWQI7zmsDfu02U Ny+ht1nwYmNguG1dT5/zUE4+AYOTtwEKfjJ0OOjxE/ChiiZhF1ezsIEBaJOjRlpymgve gUbaas1/AV1aay0ezZm7UKhmRuTsBvc/OIR4BbG7tnT0Feein0m/kykp8IreSfWsuw86 mVhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NqoI0Euluz/fjixqG9UNWuvSLhNgAyogU4r+yjRKAxE=; b=S/yXH5lyrlBt0ULm3/AfG9rjI2xNKrCLC87Een3fi5RuckLDDQUnQefmuVtfw1hL4U ty5gTTmkeCYZGAtmxq39rHn00aPd6vJ3TgYJ24UOO3fdrfdbRD0O9NcUlxme8QvFBj2A 2h+1PvqZtepj8gxKqLPU4wAPgWoUvsnxVQciQjN74xqI3ru+xyTCfi8XL9adEZnw0JZT 3NcTrBk3o6Z5/mLYIgLT4spG+lax9dHaTGss5AhKvjeRI7V6K1yIUZ6FkFurdhx3RO17 rTOLKFqCkRJtsJovZbsi+wfMgnwpN5Ua39HohqEuMKLdKGUKoRJh4ec+1dqk/FMwVvyE Qjfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="UjK/iCUD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m29si353010ejl.33.2021.06.08.11.31.15; Tue, 08 Jun 2021 11:31:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="UjK/iCUD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234002AbhFHSa4 (ORCPT + 99 others); Tue, 8 Jun 2021 14:30:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:55528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233823AbhFHSat (ORCPT ); Tue, 8 Jun 2021 14:30:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BFC2D613B9; Tue, 8 Jun 2021 18:28:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623176936; bh=BjwMVZV29dd47sjI8xClz0qNUCf6RXp1w1uXhyzZKOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UjK/iCUDPFQDLqStDVM8KencZGvDz+fUy/CyF0KT09PywTHX5dBRlNhD+wcba22l9 eHrCVonHxjkqnT+7iWGtqxt2LJb1ehPEtaq8JarMuSTesyS2c+nZJP/LBCDfMPYUyI VBJF5NhpP5F/ZJk6MHJCQBeg1yVW3QyI1fSxWUTQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+80fb126e7f7d8b1a5914@syzkaller.appspotmail.com, butt3rflyh4ck , Krzysztof Kozlowski , Jakub Kicinski Subject: [PATCH 4.4 19/23] nfc: fix NULL ptr dereference in llcp_sock_getname() after failed connect Date: Tue, 8 Jun 2021 20:27:11 +0200 Message-Id: <20210608175927.156677615@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175926.524658689@linuxfoundation.org> References: <20210608175926.524658689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Krzysztof Kozlowski commit 4ac06a1e013cf5fdd963317ffd3b968560f33bba upstream. It's possible to trigger NULL pointer dereference by local unprivileged user, when calling getsockname() after failed bind() (e.g. the bind fails because LLCP_SAP_MAX used as SAP): BUG: kernel NULL pointer dereference, address: 0000000000000000 CPU: 1 PID: 426 Comm: llcp_sock_getna Not tainted 5.13.0-rc2-next-20210521+ #9 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-1 04/01/2014 Call Trace: llcp_sock_getname+0xb1/0xe0 __sys_getpeername+0x95/0xc0 ? lockdep_hardirqs_on_prepare+0xd5/0x180 ? syscall_enter_from_user_mode+0x1c/0x40 __x64_sys_getpeername+0x11/0x20 do_syscall_64+0x36/0x70 entry_SYSCALL_64_after_hwframe+0x44/0xae This can be reproduced with Syzkaller C repro (bind followed by getpeername): https://syzkaller.appspot.com/x/repro.c?x=14def446e00000 Cc: Fixes: d646960f7986 ("NFC: Initial LLCP support") Reported-by: syzbot+80fb126e7f7d8b1a5914@syzkaller.appspotmail.com Reported-by: butt3rflyh4ck Signed-off-by: Krzysztof Kozlowski Link: https://lore.kernel.org/r/20210531072138.5219-1-krzysztof.kozlowski@canonical.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/nfc/llcp_sock.c | 2 ++ 1 file changed, 2 insertions(+) --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -121,6 +121,7 @@ static int llcp_sock_bind(struct socket if (!llcp_sock->service_name) { nfc_llcp_local_put(llcp_sock->local); llcp_sock->local = NULL; + llcp_sock->dev = NULL; ret = -ENOMEM; goto put_dev; } @@ -130,6 +131,7 @@ static int llcp_sock_bind(struct socket llcp_sock->local = NULL; kfree(llcp_sock->service_name); llcp_sock->service_name = NULL; + llcp_sock->dev = NULL; ret = -EADDRINUSE; goto put_dev; }