From patchwork Fri Mar 15 14:33:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Coelho X-Patchwork-Id: 10854883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51BA515AC for ; Fri, 15 Mar 2019 14:33:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A1972AA4F for ; Fri, 15 Mar 2019 14:33:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2ED8F2AA5E; Fri, 15 Mar 2019 14:33:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C464E2AA4F for ; Fri, 15 Mar 2019 14:33:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729288AbfCOOdc (ORCPT ); Fri, 15 Mar 2019 10:33:32 -0400 Received: from paleale.coelho.fi ([176.9.41.70]:44058 "EHLO farmhouse.coelho.fi" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729283AbfCOOdc (ORCPT ); Fri, 15 Mar 2019 10:33:32 -0400 Received: from 91-156-6-193.elisa-laajakaista.fi ([91.156.6.193] helo=redipa.ger.corp.intel.com) by farmhouse.coelho.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.91) (envelope-from ) id 1h4ntp-0004kR-An; Fri, 15 Mar 2019 16:33:30 +0200 From: Luca Coelho To: backports@vger.kernel.org Cc: Johannes Berg , Luca Coelho Date: Fri, 15 Mar 2019 16:33:18 +0200 Message-Id: <20190315143318.4714-7-luca@coelho.fi> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190315143318.4714-1-luca@coelho.fi> References: <20190315143318.4714-1-luca@coelho.fi> MIME-Version: 1.0 Subject: [PATCH 6/6] backports: genetlink: avoid NULL dereference Sender: backports-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: backports@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Berg If we fail to allocate extack, we fall back to the code path that tries to send an error *with* extack, but that will access our extack pointer. It also doesn't make sense, so just return an error back to netlink immediately and let it handle sending the error message to userspace. Signed-off-by: Johannes Berg Signed-off-by: Luca Coelho --- backport/compat/backport-genetlink.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/backport/compat/backport-genetlink.c b/backport/compat/backport-genetlink.c index 71bf45adf88d..885f17568333 100644 --- a/backport/compat/backport-genetlink.c +++ b/backport/compat/backport-genetlink.c @@ -157,12 +157,10 @@ static int backport_pre_doit(__genl_const struct genl_ops *ops, #if LINUX_VERSION_IS_LESS(4,12,0) struct netlink_ext_ack *extack = kzalloc(sizeof(*extack), GFP_KERNEL); - __bp_genl_info_userhdr_set(info, extack); + if (!extack) + return -ENOMEM; - if (!extack) { - err = -ENOMEM; - goto err; - } + __bp_genl_info_userhdr_set(info, extack); extack->__bp_doit = ops->doit; #else @@ -175,7 +173,6 @@ static int backport_pre_doit(__genl_const struct genl_ops *ops, err = family->pre_doit(ops, skb, info); #if LINUX_VERSION_IS_LESS(4,12,0) -err: if (err) { /* signal to do nothing */ extack->__bp_doit = NULL;