From patchwork Sun Aug 27 12:25:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 9923803 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F7A560380 for ; Sun, 27 Aug 2017 12:25:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 496BB28468 for ; Sun, 27 Aug 2017 12:25:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E4F32861E; Sun, 27 Aug 2017 12:25:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25A302861D for ; Sun, 27 Aug 2017 12:25:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751223AbdH0MZg (ORCPT ); Sun, 27 Aug 2017 08:25:36 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:36354 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751152AbdH0MZg (ORCPT ); Sun, 27 Aug 2017 08:25:36 -0400 Received: by mail-pf0-f193.google.com with SMTP id a2so2322594pfj.3 for ; Sun, 27 Aug 2017 05:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=WnQEmm4J0hA+09vBqyBHy7+j1/eL1ndcIPNjNNPUbCA=; b=buJMYvbSOG9OwOCBCbfUjqAa6RRWHtJcQNlfgojJsqUoIEYyvWnzLcRc5sGkOAbDzR M+vBjEnpl+vbVEOs7SmBlq9pf69NLoilzD96wVj9W7lVC59KnUsX+lZhj2eEMeHh3SIh HkX73pa8hA+0JzRdNDYfVmIO87t11uTileoz2fjykaNMaNvf4Lx4+nW4ld/NqXmpjs5q WAyMyScOWE6g3dhoRnX5SPjoRsOJI3lJwqUhHWNJXFdPBexVuo2V5TdjYT28cVNV67ti FEU+SPhu71gqkeNbxII7GsHs4TRTpJVvEtTHTKFbYPL//Y8y1DQs4manbi1NLa6Hqb17 wfnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WnQEmm4J0hA+09vBqyBHy7+j1/eL1ndcIPNjNNPUbCA=; b=CL/vGNr4Oz347uGDrwpkmp4SZ2qjDLwJ+uLGw688DtC7Id14ld9uaGCMCE5nJgNtPU 2ZaumqBUrYmmMf0ICi6+1YKInRxbOMe3a4AtboBzAIZ5TMfjSWg+2kddq47WFUGjPySW BJa7Q99y/ZdL1FqqaNJwwH4G0LnYz25PtDDDYoNt+uwG7yRtxxJB5yYmVlFYSxptkmDi e0rlnfxnCHfBjRIri4VySsjg2QHQHFkwk8HSHzUtfnWSr+1nur0ZmQ8L7j2t76HG8qOW q//SBeU6MIMm/+bGYAoJ2xQmqVz41V/JYVkVwgiY47Jt5MVre96wgwCdFvsQirYaHn3q Tg3g== X-Gm-Message-State: AHYfb5hWi35NVwTfRDyIH4EtxPVQnPc3Vb+pU6Y17QsN7cJNvfhb2R6K cDgCKkwD8K7jTWiZlhY= X-Received: by 10.99.160.92 with SMTP id u28mr4281701pgn.310.1503836734990; Sun, 27 Aug 2017 05:25:34 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id z125sm19883901pfz.108.2017.08.27.05.25.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Aug 2017 05:25:34 -0700 (PDT) From: Xin Long To: linux-scsi@vger.kernel.org Cc: "James E.J. Bottomley" , syzkaller@googlegroups.com, chunwang@redhat.com Subject: [PATCH] scsi: fix the issue that iscsi_if_rx doesn't parse nlmsg properly Date: Sun, 27 Aug 2017 20:25:26 +0800 Message-Id: <0c9fd6fbc0f5fa7b72e6ae5b82d5499a38fd375e.1503836726.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ChunYu found a kernel crash by syzkaller: [ 651.617875] kasan: CONFIG_KASAN_INLINE enabled [ 651.618217] kasan: GPF could be caused by NULL-ptr deref or user memory access [ 651.618731] general protection fault: 0000 [#1] SMP KASAN [ 651.621543] CPU: 1 PID: 9539 Comm: scsi Not tainted 4.11.0.cov #32 [ 651.621938] Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011 [ 651.622309] task: ffff880117780000 task.stack: ffff8800a3188000 [ 651.622762] RIP: 0010:skb_release_data+0x26c/0x590 [...] [ 651.627260] Call Trace: [ 651.629156] skb_release_all+0x4f/0x60 [ 651.629450] consume_skb+0x1a5/0x600 [ 651.630705] netlink_unicast+0x505/0x720 [ 651.632345] netlink_sendmsg+0xab2/0xe70 [ 651.633704] sock_sendmsg+0xcf/0x110 [ 651.633942] ___sys_sendmsg+0x833/0x980 [ 651.637117] __sys_sendmsg+0xf3/0x240 [ 651.638820] SyS_sendmsg+0x32/0x50 [ 651.639048] entry_SYSCALL_64_fastpath+0x1f/0xc2 It's caused by skb_shared_info at the end of sk_buff was overwritten by ISCSI_KEVENT_IF_ERROR when parsing nlmsg info from skb in iscsi_if_rx. During the loop if skb->len == nlh->nlmsg_len and both are sizeof(*nlh), ev = nlmsg_data(nlh) will acutally get skb_shinfo(SKB) instead and set a new value to skb_shinfo(SKB)->nr_frags by ev->type. This patch is to fix it by checking nlh->nlmsg_len properly there to avoid over accessing sk_buff. Reported-by: ChunYu Wang Signed-off-by: Xin Long Acked-by: Chris Leech --- drivers/scsi/scsi_transport_iscsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index e4b3d8f..bb4ed7b 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -3697,7 +3697,7 @@ iscsi_if_rx(struct sk_buff *skb) uint32_t group; nlh = nlmsg_hdr(skb); - if (nlh->nlmsg_len < sizeof(*nlh) || + if (nlh->nlmsg_len < sizeof(*nlh) + sizeof(*ev) || skb->len < nlh->nlmsg_len) { break; }