Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp329554imm; Sat, 1 Sep 2018 04:23:45 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYKFpPKc71nLVP7+AxOY50oE9fd8DRSWAp1xYSusswBvLyx6/63I0dXrdEqcozNFKjC1eJp X-Received: by 2002:a63:e001:: with SMTP id e1-v6mr16575847pgh.380.1535801025538; Sat, 01 Sep 2018 04:23:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535801025; cv=none; d=google.com; s=arc-20160816; b=p1sRKEn3u4ny9lQFV26bu8IZcCxUMZasWgZ7BUVFAIFhvX2u98I20CgpGdN4+KXoar GHzRpuMBD8U7PpqcMsBMix7RQE6bKDCea3uSTAMdUgA0tXVFUAnsY/0l6xzZEynz6oPa 91QMSjTYLOD6wvOZq5kFx9ZzFkC+VNV5wE6++YbsGnwE9aFJWtgQbrMSxIDg2DuXFd48 s/7shnP+JAjQZCMFT5rOmdIWhnDxBt0dSVgBOMr4lyOP2NnDzoLRzDEPMxRDXtS36lhB vseQYk8lqvZrpb91bse8bVduX/Hua74noeitMjTLhuk3CANbrJTd4uWj15WmVnvoi7Vt oe1w== 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=zpXmcdUsbwj5gElJZ0iWkZ7QP4qhOecXqtvjxnmtywM=; b=BhzjeG/CjgXSEXBNW5kJ5xIp0VQ6HEvDeXyD1s8dP51191cJGYjNEWhhUQUSTisLdP OXFPboE6bcg0hOft7bSuSnbbEpgFczcoeUxACm/ihmHt+4QR8byN0zcuayt5lwN646mj 0YnOE18cg+150s+9mmtPliiCqtCqUYuLJdOx1+zeGlgv6K3b0Cc1KZ5KB4kuWqR1capL 6rdFjj66TXHaMCSb0u4a0xEXQm54fkbugKn84xN58TwRfje3vEPpHGxvk89kdmvTN9iB 8R3/hOGbVqJ0fPCEoR1kABPFXovjoAuqC26O4g1lJLm4Ndz7g9vQ/MCDk+JEo25a7Gxi pnxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ere6ehCl; 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 y11-v6si4487261plg.237.2018.09.01.04.23.02; Sat, 01 Sep 2018 04:23:45 -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=ere6ehCl; 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 S1727234AbeIAPbv (ORCPT + 99 others); Sat, 1 Sep 2018 11:31:51 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:39233 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725973AbeIAPbv (ORCPT ); Sat, 1 Sep 2018 11:31:51 -0400 Received: by mail-pl1-f194.google.com with SMTP id w14-v6so6599846plp.6; Sat, 01 Sep 2018 04:20:10 -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=zpXmcdUsbwj5gElJZ0iWkZ7QP4qhOecXqtvjxnmtywM=; b=ere6ehClkDycpxO31dp3Q8cibj10r8TZhkL0+PrMRV1mGwCGLCVDFMjVWUDdlvDTby yLpIBCxg+Chcsrhf9KfyVREFy4Qx7oNbSqN0C2mv88IsPPtsyOpNdfN1Wj42+hxXJ5zB raA2TyyojjG0M9fCGdnYxOxUdX3tA78PsIVzwU9atNQOU5FFcrS5hVOhRfGQXLiW/c7x v2JE67Ha73eEJ3tqpaRU6IupAB0WrP0W6i7ri/OKziO3MiGlWQnfP62DJknAaOW8F3cl afRDNdalhiELY3X6jD4qZDBVTLpi4ZezUar8o9ni1tx3wZnv/TcMlf09qHu2MKKVvxEY CPkA== 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=zpXmcdUsbwj5gElJZ0iWkZ7QP4qhOecXqtvjxnmtywM=; b=EN3q3SjK4WBIxXyVxGuhZBf6N/FqPOpiq0iaBKQdDsN7h9ZJiIG7YsjMZVvegtB/Os c2gLQYOhdHuv3jR0GfTpchDTX3PQ1ZDckqfm67YgGkaEUiDR2BI78pJnI+bMpW+c/31c qSvWCCZySiAdt9PVOycKbdJbc6o1XNKgzShr49Tqo0YqjlgnlRkTID+rq2YQduSbnLg+ WmZSpNoR3woAS7UZdemKhLDCAAxRaUIeIoDut4CLG34soFpVucj0GnrFZBb2p2zbD8yW uM1B4PKIHdYhbTPvWj72jji7+//bw9O+dG5RsiIcLDaaXDQazF6Gyg/acB9UtGL4i66I sXiQ== X-Gm-Message-State: APzg51DlEfit4KHQrj2p9F80aKntsdr37WnXtcTHvVEllg22fiooWKAF A7jErfKTelbKzmZqv/4AEyY= X-Received: by 2002:a17:902:1ab:: with SMTP id b40-v6mr20057247plb.55.1535800810115; Sat, 01 Sep 2018 04:20:10 -0700 (PDT) Received: from localhost.localdomain ([2402:f000:1:4414:2913:cd09:aee0:380]) by smtp.gmail.com with ESMTPSA id p26-v6sm6599983pgn.64.2018.09.01.04.20.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Sep 2018 04:20:09 -0700 (PDT) From: Jia-Ju Bai To: davem@davemloft.net, kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] net: ipv6: route: Fix a sleep-in-atomic-context bug in ip6_convert_metrics() Date: Sat, 1 Sep 2018 19:19:58 +0800 Message-Id: <20180901111958.26529-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] kzalloc(GFP_KERNEL) net/ipv6/route.c, 2430: kzalloc in ip6_convert_metrics net/ipv6/route.c, 2890: ip6_convert_metrics in ip6_route_add net/ipv6/addrconf.c, 2322: ip6_route_add in addrconf_prefix_route net/ipv6/addrconf.c, 3331: addrconf_prefix_route in fixup_permanent_addr net/ipv6/addrconf.c, 3354: fixup_permanent_addr in addrconf_permanent_addr net/ipv6/addrconf.c, 3358: _raw_write_lock_bh in addrconf_permanent_addr 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/ipv6/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index ec18b3ce8b6d..d15e72def7c1 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -2742,7 +2742,7 @@ static int ip6_convert_metrics(struct net *net, struct fib6_info *rt, if (!cfg->fc_mx) return 0; - p = kzalloc(sizeof(*rt->fib6_metrics), GFP_KERNEL); + p = kzalloc(sizeof(*rt->fib6_metrics), GFP_ATOMIC); if (unlikely(!p)) return -ENOMEM; -- 2.17.0