Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4327610pxj; Tue, 8 Jun 2021 11:36:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+TAZtAVTGTVEY2BP9RNLo9DvbSPFzURH/6HpzQQo12gBLWM8g1F5/uwWAFHiNKzhj0Ggp X-Received: by 2002:a17:907:2be5:: with SMTP id gv37mr25855480ejc.237.1623177367917; Tue, 08 Jun 2021 11:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623177367; cv=none; d=google.com; s=arc-20160816; b=t0rvUinZr/wGQngEe46qm51kxofURfM4V+w7EeFdhXf8D9yunRknekvafi6JYSPVM0 qGJsCgmbpxYlKcQJ1tACAbX9AcdSRdl7uIh7QL+QnRbFJONj+htnk+yeC0qn49ekOzcQ XA9FDElo/3jy4qZWgaLpoJntUYhDarA33FNRfdAkUyXxIap9I2dt9NfmzINu4+szQKqD WjLVnvyJ+V/leMcVToKgd0cjuN/GjJQzbV82wr3Vv+X0QKYTkE5FJxoZBdcC3EXj7Ubn RCt4T7DKdjS6emugbaroPfEiRDkAv/HvUsHH4EHE1RHQVMOx0Yduo1op49gr518RqJKM dz4w== 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=/51O+xv+1c5g/xuyJlr0+PzBMV8jIzcZ5G79tjCz7R4=; b=wvqov3xGwGiHvCzz9r1YAx7oSNlpfIndcBxRds8cdHES64BAMa9Ug1NEypXTRSqxtK 4XqjeXBTjKcLbJI8FiH0Tw82xgu6H2+I2EGawQAN/9CQyK0+on0yqV1XyzY+PffVUQMi +OKy8kQvSyBu1ounToOyzlpF3r219jTz+ZmyAyHJuq/DOHzP8VceLGTGIqEWjwmJ/Vuo y+pfltbqG3GMNgdSK392/Ji7nRMVJ5FI1CGI4jDWngmL4rnT/1eOHUJGD1XQ4jiyFnNX J0Yz4MIi5z7IXlBSusfEg5g+8hgB/xfK7s3YVCiJEYsGktuxqVYY45fIr0e399arLsMT yz2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=u0ZqpiUd; 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 v2si381149ejk.67.2021.06.08.11.35.43; Tue, 08 Jun 2021 11:36:07 -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=u0ZqpiUd; 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 S234699AbhFHSe7 (ORCPT + 99 others); Tue, 8 Jun 2021 14:34:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:57916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233141AbhFHSd2 (ORCPT ); Tue, 8 Jun 2021 14:33:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3F105613C1; Tue, 8 Jun 2021 18:31:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177075; bh=lzdAXNyaTRliUv5aWfEYkqKJoKweSX7xsTRDbHanaig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u0ZqpiUdvUINMOqkTYUguhuyi2aNY2TCw+Jls9LUudKZKBBKFa/5UIwVHT9XyWVBe Kd8pZ8hAZpbJgzBQ6KinxuDOrzsoteOndNDJpYHp7FC/7qeNmEf0J8tHVdd0SpivXn 0C9GSvmBuLrFiivB4QvNGBB663rEk/6nDQWewWiA= 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.14 23/47] nfc: fix NULL ptr dereference in llcp_sock_getname() after failed connect Date: Tue, 8 Jun 2021 20:27:06 +0200 Message-Id: <20210608175931.240993767@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175930.477274100@linuxfoundation.org> References: <20210608175930.477274100@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 @@ -122,6 +122,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; } @@ -131,6 +132,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; }