{"id":810378,"url":"http://patchwork.ozlabs.org/api/patches/810378/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/1217baf9faf9d034ba8224cb6362b822c51a0eae.1504669632.git.lucien.xin@gmail.com/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1217baf9faf9d034ba8224cb6362b822c51a0eae.1504669632.git.lucien.xin@gmail.com>","list_archive_url":null,"date":"2017-09-06T03:47:12","name":"[net] netlink: fix an use-after-free issue for nlk groups","commit_ref":null,"pull_url":null,"state":"accepted","archived":true,"hash":"7df283c5c2e390f76a94d1a66f4c70d589aeebe6","submitter":{"id":61073,"url":"http://patchwork.ozlabs.org/api/people/61073/?format=json","name":"Xin Long","email":"lucien.xin@gmail.com"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/1217baf9faf9d034ba8224cb6362b822c51a0eae.1504669632.git.lucien.xin@gmail.com/mbox/","series":[{"id":1685,"url":"http://patchwork.ozlabs.org/api/series/1685/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=1685","date":"2017-09-06T03:47:12","name":"[net] netlink: fix an use-after-free issue for nlk groups","version":1,"mbox":"http://patchwork.ozlabs.org/series/1685/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/810378/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/810378/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"EIiInBCs\"; dkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xn8fl1xD9z9sNd\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed,  6 Sep 2017 13:47:27 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752471AbdIFDrY (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tTue, 5 Sep 2017 23:47:24 -0400","from mail-pf0-f195.google.com ([209.85.192.195]:37890 \"EHLO\n\tmail-pf0-f195.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1751956AbdIFDrV (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Tue, 5 Sep 2017 23:47:21 -0400","by mail-pf0-f195.google.com with SMTP id q76so2526238pfq.5\n\tfor <netdev@vger.kernel.org>; Tue, 05 Sep 2017 20:47:21 -0700 (PDT)","from localhost ([209.132.188.80])\n\tby smtp.gmail.com with ESMTPSA id 62sm581458pfu.4.2017.09.05.20.47.20\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tTue, 05 Sep 2017 20:47:20 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id;\n\tbh=h1O8gwkHbD/wC5o4hvYPXONkS5u71NOVx5QjbAhDnE4=;\n\tb=EIiInBCsuS6O02u1hGiTR+PwVmeQt4VCBV7RYDPNtYvgPQfKscApYXv2FDTSdeEQNo\n\t35oqe9rSppDkXiR+PvPi4hATjYhdUEkmsyYpUQ9popVVI6Gi/Gm/UyD0c6uuY5Eszb/J\n\tAfDjkKSfekQOasqZnBJxoC5ySiwWQZEZMKOXdHRwkiTDMsMJbOcoqWI20IFeJ27kqh9v\n\tVi0OzwG50yL7H4VUMXYl/KvRGT6ga8F9k16+Pg3JvljNlBlx0/FyNSUZQwuEr9/08A9u\n\tk8/JNOdxxCAEVXAsCnEyEEqU5HkfF95Frye0zl7WgbYyzL0nrwLp2Wa+wpanoxCWyPCN\n\tPl9g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id;\n\tbh=h1O8gwkHbD/wC5o4hvYPXONkS5u71NOVx5QjbAhDnE4=;\n\tb=Pipwm+VxqA0+9sl31cwwsi5Fp0snDo6NyuMkVWEGWe24p+lmKoUEQTyKHxiV8Cp4ZO\n\thRdz2eaRvl6oXbKjvQd1p6TgLs/yC+7RWPW9A7fInRNj9eWjJE7QwH5sOhl8C6TO4DwJ\n\tqcrS6ef02oWrfC8sxgGkuoVGhU3L8bT4mM5ReeKTi6u+F09n98/ng2XUrxrjEac/cbfq\n\tzJ7j6X6TS+yh9nZoDoCXYUvxZphSBOGziavKdeQv7KrhbduHfvdpiz7pe6a0FQ/tBMiZ\n\tbgPtt4TnUdZGAhN0fmGMC/iJCnKVsmi/y8SUR4BJFuUYTmb+EOs+EWJOqY3b5sM07+mV\n\tLxPw==","X-Gm-Message-State":"AHPjjUi5KUhl3L24TnZz1F3AL7rPLTdgimKrdcXKsln7j04ne7o6S59E\n\tfh33jjG89nnVYEQzhto=","X-Google-Smtp-Source":"ADKCNb4LjYMLTZB1D7tQjArAtAlzWaKm+ZGlATBhc5muhKgpqBjMCCJ+Sc52z8lpX3RrjioAE5uICQ==","X-Received":"by 10.99.164.81 with SMTP id c17mr6360584pgp.5.1504669641044;\n\tTue, 05 Sep 2017 20:47:21 -0700 (PDT)","From":"Xin Long <lucien.xin@gmail.com>","To":"network dev <netdev@vger.kernel.org>","Cc":"davem@davemloft.net, fw@strlen.de, chunwang@redhat.com,\n\tsyzkaller@googlegroups.com","Subject":"[PATCH net] netlink: fix an use-after-free issue for nlk groups","Date":"Wed,  6 Sep 2017 11:47:12 +0800","Message-Id":"<1217baf9faf9d034ba8224cb6362b822c51a0eae.1504669632.git.lucien.xin@gmail.com>","X-Mailer":"git-send-email 2.1.0","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"ChunYu found a netlink use-after-free issue by syzkaller:\n\n[28448.842981] BUG: KASAN: use-after-free in __nla_put+0x37/0x40 at addr ffff8807185e2378\n[28448.969918] Call Trace:\n[...]\n[28449.117207]  __nla_put+0x37/0x40\n[28449.132027]  nla_put+0xf5/0x130\n[28449.146261]  sk_diag_fill.isra.4.constprop.5+0x5a0/0x750 [netlink_diag]\n[28449.176608]  __netlink_diag_dump+0x25a/0x700 [netlink_diag]\n[28449.202215]  netlink_diag_dump+0x176/0x240 [netlink_diag]\n[28449.226834]  netlink_dump+0x488/0xbb0\n[28449.298014]  __netlink_dump_start+0x4e8/0x760\n[28449.317924]  netlink_diag_handler_dump+0x261/0x340 [netlink_diag]\n[28449.413414]  sock_diag_rcv_msg+0x207/0x390\n[28449.432409]  netlink_rcv_skb+0x149/0x380\n[28449.467647]  sock_diag_rcv+0x2d/0x40\n[28449.484362]  netlink_unicast+0x562/0x7b0\n[28449.564790]  netlink_sendmsg+0xaa8/0xe60\n[28449.661510]  sock_sendmsg+0xcf/0x110\n[28449.865631]  __sys_sendmsg+0xf3/0x240\n[28450.000964]  SyS_sendmsg+0x32/0x50\n[28450.016969]  do_syscall_64+0x25c/0x6c0\n[28450.154439]  entry_SYSCALL64_slow_path+0x25/0x25\n\nIt was caused by no protection between nlk groups' free in netlink_release\nand nlk groups' accessing in sk_diag_dump_groups. The similar issue also\nexists in netlink_seq_show().\n\nThis patch is to defer nlk groups' free in deferred_put_nlk_sk.\n\nReported-by: ChunYu Wang <chunwang@redhat.com>\nAcked-by: Florian Westphal <fw@strlen.de>\nSigned-off-by: Xin Long <lucien.xin@gmail.com>\n---\n net/netlink/af_netlink.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)","diff":"diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c\nindex 5acee49..94a61e6 100644\n--- a/net/netlink/af_netlink.c\n+++ b/net/netlink/af_netlink.c\n@@ -691,6 +691,9 @@ static void deferred_put_nlk_sk(struct rcu_head *head)\n \tstruct netlink_sock *nlk = container_of(head, struct netlink_sock, rcu);\n \tstruct sock *sk = &nlk->sk;\n \n+\tkfree(nlk->groups);\n+\tnlk->groups = NULL;\n+\n \tif (!refcount_dec_and_test(&sk->sk_refcnt))\n \t\treturn;\n \n@@ -769,9 +772,6 @@ static int netlink_release(struct socket *sock)\n \t\tnetlink_table_ungrab();\n \t}\n \n-\tkfree(nlk->groups);\n-\tnlk->groups = NULL;\n-\n \tlocal_bh_disable();\n \tsock_prot_inuse_add(sock_net(sk), &netlink_proto, -1);\n \tlocal_bh_enable();\n","prefixes":["net"]}