From patchwork Fri Jun 16 21:57:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Rose X-Patchwork-Id: 777216 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wqDkk5xGDz9s7F for ; Sat, 17 Jun 2017 07:57:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tn9eb75M"; dkim-atps=neutral Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 05FE3B6E; Fri, 16 Jun 2017 21:57:47 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 82E0BB4C for ; Fri, 16 Jun 2017 21:57:46 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 34433A6 for ; Fri, 16 Jun 2017 21:57:46 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id v18so7925964pgb.3 for ; Fri, 16 Jun 2017 14:57:46 -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=ZieqwxZollRkJCROS5GNqrJOzbYQUhNsZbavLtM/sHs=; b=tn9eb75MrWWt7RSgxO/II+9pgqAaNaYM1KpnNWLfn5Kzf/CDnCEhMsVnZv7ThAiRPx NjhVbEtbsGYR8TAXD0r0c7Z0yFXlByL+xhqgoffCvfMsWzPDZ09kyLLfVKfUNKsi5RSz d8IzkBUrspTkbtvMmn8GhHtEXnkvxDamvOGbrXfNwekxqW49ch0qbXN0GaY9crrHF5ya oVLjLGhpCc+TCcgIdpxWwsRgB0rMZXKV9TaU/xjJ4OYk9k1O5HO1MkazqiqdFDI1qVwO EQqCfi8FhL/9162s0VDhQvUS3eBa4blxe1BDdpVPKzxQE/k7zYwT0nUvOrakFIGFup0i AUHw== 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=ZieqwxZollRkJCROS5GNqrJOzbYQUhNsZbavLtM/sHs=; b=sUPS11BT2rnjv5Gdqzk7DrzzhXn79UGFimg6XqyxU8JPoLYK4avzoHHEuWl6gnp+bk mnlIl2zLu0GYfikZtGkXZJV0wKToe3nxDZ19U0wBDJPuCjkrEvruuszhWhZha9vOTsGK M9bmACLronjjFOJCHXIirN6/qg0nDXF26ppfcUprggb2hDZU9Ppj7nfJD4jkdiabEAby YW0lKabCBBi+XKBl3Nd/Q0RCO77169EjoE7HCjfQahKQ3G4ofsA7wr5JEIkiXgtxcYQq W0+Kk4EGt8qzlPvUGizFPpheFZk93Hs1Snx/01DZHCd3tRj3K2qRQp6v0GxW2FIy23qV +0/Q== X-Gm-Message-State: AKS2vOyKfaEsB/brv4xz6z7balTlo88XQcx2ehX3HM5IWgFUi4IP5Fte VmMKp0sgkXoC6GSn X-Received: by 10.84.132.14 with SMTP id 14mr12502024ple.271.1497650265452; Fri, 16 Jun 2017 14:57:45 -0700 (PDT) Received: from gizo.domain (71-34-113-80.ptld.qwest.net. [71.34.113.80]) by smtp.gmail.com with ESMTPSA id a69sm6639518pfg.91.2017.06.16.14.57.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jun 2017 14:57:44 -0700 (PDT) From: Greg Rose To: dev@openvswitch.org Date: Fri, 16 Jun 2017 14:57:41 -0700 Message-Id: <1497650261-12918-1-git-send-email-gvrose8192@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH V2] compat: Restrict __ro_after_init usage X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The attribute __ro_after_init was introduced in Linux kernel 4.5. If a data structure is given this attribute then after the driver module loads the memory page where the data resides will be marked read only. The compat code in cache.h always defines __ro_after_init if it is not already defined so that it can be used as an attribute for the datapath genl_family structure definitions. If __ro_after_init is defined then it is used "as-is" where it will apply the read only attribute after driver initialization. This is incorrect usage for the Generic Netlink genl_family structure definitions prior to Linux kernel 4.10. The genl_family structure in those kernels includes a list header member that will be written to when the generic netlink family is unregistered. This will cause a subsequent page fault and kernel panic because at this time the genl_family structure data has been marked read only in the page descriptor. A new compat macro is introduced in acinclude.m4 to detect when the genl_family structure has the family_list list header as a member. In this case HAVE_GENL_FAMILY_LIST is defined and if __ro_after_init is also defined then it is undefined and redefined as empty. This will prevent the genl_family data structure from being marked read only in kernels 4.5 through 4.9 and thus prevent the page fault when the generic netlink families in datapath.c are unregistered. V2 - Remember Fixes and Signed-off-by tags this time. Fixes: ba63fe260bd5 ("datapath: Allow compile against current net-next.") Signed-off-by: Greg Rose --- acinclude.m4 | 3 +++ datapath/linux/compat/include/linux/cache.h | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/acinclude.m4 b/acinclude.m4 index 22cb897..2145ecc 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -736,6 +736,9 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [ OVS_FIND_PARAM_IFELSE([$KSRC/include/net/netfilter/ipv6/nf_defrag_ipv6.h], [nf_defrag_ipv6_enable], [net], [OVS_DEFINE([HAVE_DEFRAG_ENABLE_TAKES_NET])]) + OVS_GREP_IFELSE([$KSRC/include/net/genetlink.h], [family_list], + [OVS_DEFINE([HAVE_GENL_FAMILY_LIST])]) + if cmp -s datapath/linux/kcompat.h.new \ datapath/linux/kcompat.h >/dev/null 2>&1; then diff --git a/datapath/linux/compat/include/linux/cache.h b/datapath/linux/compat/include/linux/cache.h index 917defa..35da4e7 100644 --- a/datapath/linux/compat/include/linux/cache.h +++ b/datapath/linux/compat/include/linux/cache.h @@ -3,8 +3,15 @@ #include_next +#ifdef HAVE_GENL_FAMILY_LIST +#ifdef __ro_after_init +#undef __ro_after_init +#endif /* #ifdef __ro_after_init */ +#define __ro_after_init +#else #ifndef __ro_after_init #define __ro_after_init -#endif +#endif /* #ifndef __ro_after_init */ +#endif /* #ifdef HAVE_GENL_FAMILY_LIST */ #endif