Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp290911imm; Sat, 1 Sep 2018 03:01:58 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYzps2pq271ksNr++KGa5yPmkDBNdWZ3oHXNPnPNGBB9HOVVAuxjBOsIg4nfInt+kUscfxK X-Received: by 2002:a62:d544:: with SMTP id d65-v6mr20010308pfg.107.1535796118033; Sat, 01 Sep 2018 03:01:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535796118; cv=none; d=google.com; s=arc-20160816; b=ZN/FCx+KsTP3xkgVoDwHTP3T52s4VRIWnOxSGLIGq/rAh4HlJa8SQu9uoK3InTa/B9 Hl4mFiQVCr60JYm4zlR/xjhESeIC1SNEweFezZCAsXPP/JdAhFNausFYQ0NI72HD7xpm +LtNw/d165eA9/USHw+2IHT/Ou5hQdpgM9jenBYcYC3AHSPrlAfRBR8j1MOVhtnMhh+m m1ila0uKVNfQ/a/+vmtkp/rJLbuAB6X8GMnum+d5lRclPhHA3rE57079qLUQZAfQp6jB 8dRRYUs+piwJBaC/77AnFFco/DKLdCIuPX6zluvqi1+n8Y4X7BJ58cGngKEOSy9zu8Z7 wICg== 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=j9cDap1HW/F+JokRW7P2bqq7Yy5kZvZQGSg9p1J42uI=; b=NmWlGei4Nnz67VHb74oUUpT77tmgg50SXeP49kuFYcBgSCfd+9FjiVbw76/hIBS2Si chOLSTRrxjNX8GGMmfPelcp5Un08hvc9toJYyCK+AQEQdGfpEX02atiuC0Od6RKbrXhT ObhuBmga5LIncXqEQJoPfCKNyRjjqJiwMIdfvqZROeYn+xkkae3gobhHrxlAnIzDmIAZ G/G89JS8Z110W+Nb4N+wfb4og0DWKYqkwy2Q4ibl2Kptik/u5MVzu5bIuiZyug8cc+wx 7of/A1iwOFqk5wPSzhVsKYzeTjNQxC174WQdL8X7QqV9BYhibp0wPBMhWUXBSnbNMB5O Agzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L3Fw3YsJ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r14-v6si12049806pgl.490.2018.09.01.03.01.40; Sat, 01 Sep 2018 03:01:57 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=L3Fw3YsJ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727434AbeIAOMF (ORCPT + 99 others); Sat, 1 Sep 2018 10:12:05 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36161 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726926AbeIAOMF (ORCPT ); Sat, 1 Sep 2018 10:12:05 -0400 Received: by mail-pl1-f196.google.com with SMTP id e11-v6so6554832plb.3; Sat, 01 Sep 2018 03:00:37 -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=j9cDap1HW/F+JokRW7P2bqq7Yy5kZvZQGSg9p1J42uI=; b=L3Fw3YsJXC/n8P2PW3PjBrwoStt1x6fgHVkM0F9Av6hiSoVwuQqOyEJ0IL9SoDBBK/ 0m6k00MSvwjjaTRSXpnxT8JfmP/cz2Uw91NtyF+qdzja/Y7sdd080n5S8NgwAieEPxxL ZipZun4XnU5y0PO2RW1zmk5VuVeuwRGPnZAmMt7zoUXYVXEZyYzEG8SH09AJkREbkQJh bcBS696OtWvGKFc6TZltqENRU7ZrtiWQTn1mtoJQJUqs3bKlLoG+ur4hLAgwMtIEnFDY VQbvWy6F82P32u5ZIptCv1X1yU27vT5sAB5+NPKH8lARMVwqKZbQbyVqiMQSirShv7xw 6CrA== 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=j9cDap1HW/F+JokRW7P2bqq7Yy5kZvZQGSg9p1J42uI=; b=abf+tW2px/UDKUtU5pjRgQQKx7zHb4uxNLvsxBceL0MXDZH4DtenFpfttrDnKPZUEf izxt3PudHJglmi4PN2CGuhc5pos0wxDrC2xbDC1yNV5/Gg5zCIZj4poeXZfqn1Nf+M4K AF4DTT1y0cxjj5qZufhQVzBFr2e8x7rOa+rCUa5VZLa7oHIb2FiO1jDA3Cfxzsaajilf 1/qpJHIYumJortDo4BxPoohIidcW8pDQ9WQKZo1zfnMiBya/BcT/0CQnTubjVOslIT14 6Z7yQ0LDPKtW+oD/MkAnTdssGZ/O5lzzqNocHE/QXhhjqswXitPoRaAgq/Tld9iPMR1b f3HQ== X-Gm-Message-State: APzg51Bk/OMXxqyaWNuNyx9mwxxUmJwhd7TKHKz9xPtKGrajxl6BrFjW YBS/Fq9yzqN+hnOgCcPErhQ= X-Received: by 2002:a17:902:a5cc:: with SMTP id t12-v6mr19135616plq.6.1535796036964; Sat, 01 Sep 2018 03:00:36 -0700 (PDT) Received: from localhost.localdomain ([2402:f000:1:4414:2913:cd09:aee0:380]) by smtp.gmail.com with ESMTPSA id x3-v6sm14413798pgv.61.2018.09.01.03.00.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Sep 2018 03:00:36 -0700 (PDT) From: Jia-Ju Bai To: davem@davemloft.net, ktkhai@virtuozzo.com, viro@zeniv.linux.org.uk, adobriyan@gmail.com, dvlasenk@redhat.com, xiyou.wangcong@gmail.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] net: scm: Fix a possible sleep-in-atomic-context bug in scm_fp_copy() Date: Sat, 1 Sep 2018 18:00:26 +0800 Message-Id: <20180901100026.16956-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The kernel module may sleep with holding a spinlock. The function call paths (from bottom to top) in Linux-4.16 are: [FUNC] kmalloc(GFP_KERNEL) net/core/scm.c, 85: kmalloc in scm_fp_copy net/core/scm.c, 161: scm_fp_copy in __scm_send ./include/net/scm.h, 88: __scm_send in scm_send net/unix/af_unix.c, 1600: scm_send in maybe_init_creds net/unix/af_unix.c, 1983: maybe_init_creds in unix_stream_sendpage net/unix/af_unix.c, 1973: spin_lock in unix_stream_sendpage To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC. This bug is found by my static analysis tool DSAC. Signed-off-by: Jia-Ju Bai --- net/core/scm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/scm.c b/net/core/scm.c index b1ff8a441748..49548f81c45b 100644 --- a/net/core/scm.c +++ b/net/core/scm.c @@ -82,7 +82,7 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp) if (!fpl) { - fpl = kmalloc(sizeof(struct scm_fp_list), GFP_KERNEL); + fpl = kmalloc(sizeof(struct scm_fp_list), GFP_ATOMIC); if (!fpl) return -ENOMEM; *fplp = fpl; -- 2.17.0