From patchwork Tue Apr 2 13:08:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Coelho X-Patchwork-Id: 10881667 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 E4E09922 for ; Tue, 2 Apr 2019 13:08:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE20B26224 for ; Tue, 2 Apr 2019 13:08:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1B512841F; Tue, 2 Apr 2019 13:08: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 C28C326224 for ; Tue, 2 Apr 2019 13:08:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730581AbfDBNIb (ORCPT ); Tue, 2 Apr 2019 09:08:31 -0400 Received: from paleale.coelho.fi ([176.9.41.70]:49396 "EHLO farmhouse.coelho.fi" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730245AbfDBNIa (ORCPT ); Tue, 2 Apr 2019 09:08:30 -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 1hBJ9Q-0006zx-M3; Tue, 02 Apr 2019 16:08:29 +0300 From: Luca Coelho To: backports@vger.kernel.org Cc: Luca Coelho Date: Tue, 2 Apr 2019 16:08:23 +0300 Message-Id: <20190402130823.13965-1-luca@coelho.fi> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [PATCH] backport: check for failure when allocating ops in genetlink Sender: backports-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: backports@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Luca Coelho We were not checking if the allocation failed in backport_genl_register_family(), which could lead to NULL pointer dereferences later. Fix that. Signed-off-by: Luca Coelho --- backport/compat/backport-genetlink.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backport/compat/backport-genetlink.c b/backport/compat/backport-genetlink.c index 885f17568333..16971ec34e38 100644 --- a/backport/compat/backport-genetlink.c +++ b/backport/compat/backport-genetlink.c @@ -220,7 +220,11 @@ int backport_genl_register_family(struct genl_family *family) /* we append one entry to the ops to find our family pointer ... */ ops = kzalloc(sizeof(*ops) * (family->n_ops + 1), GFP_KERNEL); + if (!ops) + return -ENOMEM; + memcpy(ops, family->ops, sizeof(*ops) * family->n_ops); + /* * Remove policy to skip validation as the struct nla_policy * memory layout isn't compatible with the old version