Received: by 10.223.185.116 with SMTP id b49csp5420391wrg; Wed, 7 Mar 2018 11:25:41 -0800 (PST) X-Google-Smtp-Source: AG47ELu0hQKFDSmaucKM83xlTCckkjBJ526YOG3WoMWOvzc7QmNxfK2Kq9kBEzuM844I8c8zC4FG X-Received: by 2002:a17:902:529:: with SMTP id 38-v6mr21063190plf.327.1520450741241; Wed, 07 Mar 2018 11:25:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520450741; cv=none; d=google.com; s=arc-20160816; b=C4lBvYxCpfVISa9VibultKXXnqEQQLnFFa+GD4pd5UmcWbJfHAx7r6f73Tfyu7OXSn W7+ejUInwTjQhYOmDxUiRTpw1WoC/u5F9BHGvI+nXYA8X9h19Wu+yJLIOXj+D0hagauO 8v0HqQd2qYdSi8vuCTJo3LE3Y6TSSOOWI0dbGlcRw8SffIxubFdu2fS/IBAMwyNwaxa0 /Q6+huVjh5OkarVezyZQHebbSarmwlrRNFW8ktnzZwhm5huTF+Vrx+6Jlfn8gR0SGoMb ijucM00b4IiJq6BBzs7XHX6NV2xXMyDlhqGSE5LaiejfQTFRg1TdJ0lCecVT5N7W1mvT Pg2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=SIkQJEg4fzKybDAjTz38b5JfGaSZqtgpDYlm1bPPWIw=; b=XNgITJkUw8+Nbv2zZUGDRyoD8ohqAglM+/f2s8/wY0/81Q8cmIGD9MI0k1jzKOVTZ/ H076RtDtXS3FTySXpEtvBGrcc24m0gpIsJ5XF2kbk9sofDYCFYzK3uEkZ1vlbW6m0ikh 7YXXfzlbbwlvaHo+2xsRTQXxroTgWCignepwXQ+FEUmyl+lU/I07YWoDTamHdJZCwAs8 +u8mLyPPGd+W+Oa5iURc4ZPWWmU6N6pwILBbWza4z4fK9Bg+pppNMkiaD6dXaOw86oe5 UqoizCX2Y1P/j6Y+ux9jwae+V8s3AhWwKOkH78LTNVhfFDWH+ICbQljUh1H7r757xdfe whtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lH8bx8F6; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x205si11652400pgx.402.2018.03.07.11.25.26; Wed, 07 Mar 2018 11:25:41 -0800 (PST) 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=@google.com header.s=20161025 header.b=lH8bx8F6; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933612AbeCGTYa (ORCPT + 99 others); Wed, 7 Mar 2018 14:24:30 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:44044 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933415AbeCGTY2 (ORCPT ); Wed, 7 Mar 2018 14:24:28 -0500 Received: by mail-pf0-f195.google.com with SMTP id 17so1327704pfw.11 for ; Wed, 07 Mar 2018 11:24:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=SIkQJEg4fzKybDAjTz38b5JfGaSZqtgpDYlm1bPPWIw=; b=lH8bx8F6m1KgNa11drYG0V5i9PFQRkY6l0RCDQj/WhOrCQi05DfN71PbkfPMQnN/W6 hWg2O1fcA66NR4YTEsfIk7xQ/aJ+6ZpetHdFdq5OJQOEUaSC9hLeafi97S+5xqNe257L tiWA4EgS7frVTfCB8xzUZKC0Zyefd+Wb+bFBoWw1uXkrwGiIkvEO7JBqB6B0ylqVUY9F vX+NMJP0HB25xtAQ55kPTY9lYGVIjs0DsdZue6b1t/r70noTNn91MmqNxqe91Phoa2WT 58i92q4mD7B6deKxejRct+pHi+hwN7KcSdI7vHrR7gGU1E1c9fgs8r6grP/LC+NECBIk MeUg== 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=SIkQJEg4fzKybDAjTz38b5JfGaSZqtgpDYlm1bPPWIw=; b=IegkoSE4KDueWkUeEt+PZJQvL9cPvDD+VMYAr8RsOo48l3uMAHYhkegTCkgsPSaGYg a6xdDdv9qo4bU/qyaGBiTxCjmGkx0Q0H/Z7pbLXBAYtSqVqZm4EzwEu0WgpLptMq2WNp nHqNSIxtTlNA1hbxO14M9b2Fs47Sf0OXMEzM/kl/m4MWcRB3Cew+bxKlTqzpLdhZbcUu 1lJzo4LebAh3g37Wnikx62JSMj0BI9POAOdEE6lVya1c8h6ZW7qqNwo+WxM//Vj0VkGQ 6aaJCYHmBPhzMVSjuPuZ/j4BvvdXa3COZTR/M6py0Dzcia/QQhp86UOCOm42+o++kOJ2 dgwQ== X-Gm-Message-State: APf1xPCdvSsb3kkaAZqqAra3R3mTIkgvfSNPqF1UivSs1uKEzpU9VH3T 2R0voU3Tjil28bA/HoN5VdcDRg== X-Received: by 10.99.108.66 with SMTP id h63mr18583548pgc.177.1520450667455; Wed, 07 Mar 2018 11:24:27 -0800 (PST) Received: from hackmann.mtv.corp.google.com ([2620:0:1000:1601:82f7:8f1:8c08:a97a]) by smtp.gmail.com with ESMTPSA id v144sm6641888pgb.63.2018.03.07.11.24.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Mar 2018 11:24:26 -0800 (PST) From: Greg Hackmann To: Steffen Klassert , Herbert Xu , "David S. Miller" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Hackmann , stable@vger.kernel.org Subject: [PATCH] net: xfrm: use preempt-safe this_cpu_read() in ipcomp_alloc_tfms() Date: Wed, 7 Mar 2018 11:24:16 -0800 Message-Id: <20180307192416.233202-1-ghackmann@google.com> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org f7c83bcbfaf5 ("net: xfrm: use __this_cpu_read per-cpu helper") added a __this_cpu_read() call inside ipcomp_alloc_tfms(). Since this call was introduced, the rules around per-cpu accessors have been tightened and __this_cpu_read() cannot be used in a preemptible context. syzkaller reported this leading to the following kernel BUG while fuzzing sendmsg: BUG: using __this_cpu_read() in preemptible [00000000] code: repro/3101 caller is ipcomp_init_state+0x185/0x990 CPU: 3 PID: 3101 Comm: repro Not tainted 4.16.0-rc4-00123-g86f84779d8e9 #154 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014 Call Trace: dump_stack+0xb9/0x115 check_preemption_disabled+0x1cb/0x1f0 ipcomp_init_state+0x185/0x990 ? __xfrm_init_state+0x876/0xc20 ? lock_downgrade+0x5e0/0x5e0 ipcomp4_init_state+0xaa/0x7c0 __xfrm_init_state+0x3eb/0xc20 xfrm_init_state+0x19/0x60 pfkey_add+0x20df/0x36f0 ? pfkey_broadcast+0x3dd/0x600 ? pfkey_sock_destruct+0x340/0x340 ? pfkey_seq_stop+0x80/0x80 ? __skb_clone+0x236/0x750 ? kmem_cache_alloc+0x1f6/0x260 ? pfkey_sock_destruct+0x340/0x340 ? pfkey_process+0x62a/0x6f0 pfkey_process+0x62a/0x6f0 ? pfkey_send_new_mapping+0x11c0/0x11c0 ? mutex_lock_io_nested+0x1390/0x1390 pfkey_sendmsg+0x383/0x750 ? dump_sp+0x430/0x430 sock_sendmsg+0xc0/0x100 ___sys_sendmsg+0x6c8/0x8b0 ? copy_msghdr_from_user+0x3b0/0x3b0 ? pagevec_lru_move_fn+0x144/0x1f0 ? find_held_lock+0x32/0x1c0 ? do_huge_pmd_anonymous_page+0xc43/0x11e0 ? lock_downgrade+0x5e0/0x5e0 ? get_kernel_page+0xb0/0xb0 ? _raw_spin_unlock+0x29/0x40 ? do_huge_pmd_anonymous_page+0x400/0x11e0 ? __handle_mm_fault+0x553/0x2460 ? __fget_light+0x163/0x1f0 ? __sys_sendmsg+0xc7/0x170 __sys_sendmsg+0xc7/0x170 ? SyS_shutdown+0x1a0/0x1a0 ? __do_page_fault+0x5a0/0xca0 ? lock_downgrade+0x5e0/0x5e0 SyS_sendmsg+0x27/0x40 ? __sys_sendmsg+0x170/0x170 do_syscall_64+0x19f/0x640 entry_SYSCALL_64_after_hwframe+0x42/0xb7 RIP: 0033:0x7f0ee73dfb79 RSP: 002b:00007ffe14fc15a8 EFLAGS: 00000207 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f0ee73dfb79 RDX: 0000000000000000 RSI: 00000000208befc8 RDI: 0000000000000004 RBP: 00007ffe14fc15b0 R08: 00007ffe14fc15c0 R09: 00007ffe14fc15c0 R10: 0000000000000000 R11: 0000000000000207 R12: 0000000000400440 R13: 00007ffe14fc16b0 R14: 0000000000000000 R15: 0000000000000000 Cc: stable@vger.kernel.org Signed-off-by: Greg Hackmann --- net/xfrm/xfrm_ipcomp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c index ccfdc7115a83..a00ec715aa46 100644 --- a/net/xfrm/xfrm_ipcomp.c +++ b/net/xfrm/xfrm_ipcomp.c @@ -283,7 +283,7 @@ static struct crypto_comp * __percpu *ipcomp_alloc_tfms(const char *alg_name) struct crypto_comp *tfm; /* This can be any valid CPU ID so we don't need locking. */ - tfm = __this_cpu_read(*pos->tfms); + tfm = this_cpu_read(*pos->tfms); if (!strcmp(crypto_comp_name(tfm), alg_name)) { pos->users++; -- 2.16.2.395.g2e18187dfd-goog