Received: by 10.223.185.116 with SMTP id b49csp5597663wrg; Wed, 7 Mar 2018 14:45:35 -0800 (PST) X-Google-Smtp-Source: AG47ELtwPKeFq3rhdYIgHvtdrsG1N0rTU3dXX4ANCxRZnzyIyqcfQIBKqtUXykmsWgG3e3B4obPS X-Received: by 10.99.109.138 with SMTP id i132mr19734852pgc.417.1520462735864; Wed, 07 Mar 2018 14:45:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520462735; cv=none; d=google.com; s=arc-20160816; b=vMq2CebnshD4UxNjHNQRX2+R2PRgXEAHyk8sYvJaojFWA/vYve/hLQtuCEpzXQrijp HGbG0Pv1wXzoq+8GfhN0tG6PpUKtNujchQd2XKO5ZtCYWgOyeJXWw+zDUd2dWbd+WGYp 7NVWJsztUV/TT62BG9JvvRSmsySl4mwAP/bxQynS9FkbSZSdBXBROKlOD3V+t2JoYnOi yYF6nT+NekI5H8QuNbwIKY5h1S+l5pg+noVYaK/Zzd/1+E40hOMvjOq+uQ/9aiz+gxRt c/ZhDmeCjBy4sBGDp/yUX2kvjbMYoNGG6Ro0DegGByPTjIVtTSg4w3taLr5cBM0BHOjf K4+g== 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=eLSCxJEBFAIqumlqw1whbRc5njto5Rk387JlY+KYr70=; b=NsOsco56bN12fi4o/ZvZPPgiJeM5zvEEgVrBlm6JSDa8p92oU4iGO46hzXCBrEapKp I1CAWCb2rTzc9eQPbP79jZlC2Y7eRlNLk05+Zw2J/tHdAC29vah5zACWK5d9i4Jqk6tF lHL6IMlP6r7UtNVuBCqhmV/u4hC96y89JzWw/EoYZXfKqK8r99e8Zv49oL463iW3tGoq uo4ynlamzIg80TkPO9LRo/e8ouigQhSbo6cRRv2AAzxDcSS/08k+HtLVA4XLGtUF1uUb 9m8fYYlFnW5S/Dk6Q+LNcB3/xHr9uIZLf8Qh6IJfk8he8v4izDx5PNrfUH1C0HLbrPLz CdUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Gaeat415; 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 g10-v6si13550022plk.730.2018.03.07.14.45.21; Wed, 07 Mar 2018 14:45:35 -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=Gaeat415; 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 S934405AbeCGWnq (ORCPT + 99 others); Wed, 7 Mar 2018 17:43:46 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34877 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934175AbeCGWng (ORCPT ); Wed, 7 Mar 2018 17:43:36 -0500 Received: by mail-pf0-f194.google.com with SMTP id y186so1550889pfb.2 for ; Wed, 07 Mar 2018 14:43:36 -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=eLSCxJEBFAIqumlqw1whbRc5njto5Rk387JlY+KYr70=; b=Gaeat4154bp6Fjp2WxamrsAXjwOY1/cVIDatmpp9z9fCOLHLRORXR8c3NkEv6Rb7/S wx+7loryAPPVwCnTP5Yh5vLXLqIGkcY5cCC5qTH90S5VkojOPQ71XdBrjiTM8oNOjQCA WxkPQlnC4VS+J/3mb8TWwm7rtWfN9t+F/EzywpJ/n1/eN8wCJ8oGTOj2kL7VPu9201ST Jg8T/AEDU710hggP4ygd3yhttFfQcW4HraF6Ug0LfBi95CdbDqy2DUKlBHPG9dU4N0d7 RlaApIq6XnRRzsFiviRMv68YHFuMcvxpnOHatWqB1JRuaRmlM8AZJ+dmVMw1K3zDFJzQ dHgw== 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=eLSCxJEBFAIqumlqw1whbRc5njto5Rk387JlY+KYr70=; b=VRTJpe7NZYWsCikEI5bl/oq1D8t3oGWVIUCm1nNJVkOTpHiMJ831HL97ZZrsVdkC+r MrMQBAdiTVpYx0E+hWhElsWz9cgaWYv+CRTkM8Yf3Dc8Js+uDTgSgbk+MWmZMQkSb+x/ HtafawOObyIfAN2Gez6qx+sHtk7IbQoIKkGPZL+WrCJ0iGYFJr2Xh6g4NA4OQ+7Z8yF5 sxku8Koyy2Cjs3XIVHbWtRMQrjb3+p8arh9807EVVogFI2K9N2H5ognv8pUYdjMgE+uc 8ay+ap+3o/sqsvTPKu3nBxuGhyJjnBkPl1JBAQ/C7labX73D8DBLEZ5F8Z59DArqyuO3 P/6w== X-Gm-Message-State: APf1xPChbAJ4mCC8Vi8ZKt0gxUF6mzaatam2c5rwC8bpXE4jADMuLViy Cnulj3We1KLZgrIBEfhdp+DQnA== X-Received: by 10.98.102.82 with SMTP id a79mr24155952pfc.138.1520462615344; Wed, 07 Mar 2018 14:43:35 -0800 (PST) Received: from hackmann.mtv.corp.google.com ([2620:0:1000:1601:82f7:8f1:8c08:a97a]) by smtp.gmail.com with ESMTPSA id p6sm37161286pfg.183.2018.03.07.14.43.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Mar 2018 14:43:34 -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 Subject: [PATCH v2 net] net: xfrm: use preempt-safe this_cpu_read() in ipcomp_alloc_tfms() Date: Wed, 7 Mar 2018 14:42:53 -0800 Message-Id: <20180307224253.152470-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(). At the time, __this_cpu_read() required the caller to either not care about races or to handle preemption/interrupt issues. 3.15 tightened the rules around some per-cpu operations, and now __this_cpu_read() should never be used in a preemptible context. On 3.15 and later, we need to use this_cpu_read() instead. 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 Signed-off-by: Greg Hackmann --- v2: expand commit log to clarify that kernel 3.15 and later are impacted 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