From patchwork Fri Mar 30 08:53:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salvatore Mesoraca X-Patchwork-Id: 10317415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1A7C7602A7 for ; Fri, 30 Mar 2018 08:53:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CB762A566 for ; Fri, 30 Mar 2018 08:53:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0123F2A56A; Fri, 30 Mar 2018 08:53:38 +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=-4.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 2C5822A566 for ; Fri, 30 Mar 2018 08:53:37 +0000 (UTC) Received: (qmail 22088 invoked by uid 550); 30 Mar 2018 08:53:32 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 22068 invoked from network); 30 Mar 2018 08:53:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=qGnZyqfAqz97h1IJ1jKpe0mHDRkFqYwhjmIcLz/kaRs=; b=OSmL0gPrSeIhw8Uf+qd1coQpEHNLCU/OziVtTsK2WuQMDNMCnSvV0hLlQcr63uFXMm 0CbdgJfhZ8DThuOQrzlNgmheBeY5zB2x6ITOXfOSBSfaWWtLU8hbIRd1g+4BXNUR7QV0 bSfT3n829oTPo1n1kSWak9s7wgNX+lMF1rasgkmI1EUMIdpNU3y5NjW7TahxxOuRsZyK JF+41G2v6lGoQv0DTkkO3Ac64a15okInlBkjG+ibp0KEm846gl+kauuKeVXmre9gSkAq sNEsRoiUsUe4juwJp3EPRBeN9n5D31r1va2YTwwxDrgmdXd0Y4gqIWlR0GZ+pOJZNS/1 HmOA== 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=qGnZyqfAqz97h1IJ1jKpe0mHDRkFqYwhjmIcLz/kaRs=; b=fOcbMh53Xu3/oEayDFtYgyTvYsRtLNhyOjwSkYAwN35eY5+Q1nYF8XwCp3S0IKoUd4 WI+Rw29rBiA4pb4DZmfwD8tPAIHsQeJ0731nyAWhbo0QtlbF7bVIMnq2QEIbP9nJpBde hcI0Kem7NqgRDWVvypJxvPsuu1x2mUQ38pl/Bj0D0fWU4RSsIgeQbCsKxpbTrGaZec01 T8ugXNPGfDwGXNrgvnRImkWKFD3vte381bumdhdxI+vWqfjVKFAS+xGv/pV7HPX/TghJ TxLr6I40VZEJwDME+oyo+MVl5Oy2S78an+I0Gm/vm0u91t6y9SvVqez7Sur4jm+p7jlt BXPw== X-Gm-Message-State: AElRT7GIRcK/lUWX15OH8nrscR3wL3ntvNbS6RmQqj7q75EfdgDhMHpd rNS1jE6iHCGQwHjjFl0o0dw= X-Google-Smtp-Source: AIpwx4/zZCG2/APoVVbY0+xBotDn+Eyu6/9ItXAFaOAQlXI/0i1Yul3jMj01ENdPCzB796YN/8fWrA== X-Received: by 10.28.116.20 with SMTP id p20mr1717717wmc.24.1522400000792; Fri, 30 Mar 2018 01:53:20 -0700 (PDT) From: Salvatore Mesoraca To: linux-kernel@vger.kernel.org Cc: kernel-hardening@lists.openwall.com, Ingo Molnar , Kees Cook , Salvatore Mesoraca , Steven Rostedt Subject: [v2] ftrace: drop a VLA in module_exists() Date: Fri, 30 Mar 2018 10:53:08 +0200 Message-Id: <1522399988-8815-1-git-send-email-s.mesoraca16@gmail.com> X-Mailer: git-send-email 1.9.1 X-Virus-Scanned: ClamAV using ClamSMTP Avoid a VLA[1] by using a real constant expression instead of a variable. The compiler should be able to optimize the original code and avoid using an actual VLA. Anyway this change is useful because it will avoid a false positive with -Wvla, it might also help the compiler generating better code. [1] https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Salvatore Mesoraca --- kernel/trace/ftrace.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index eac9ce2..16bbf06 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -3902,14 +3902,13 @@ static bool module_exists(const char *module) { /* All modules have the symbol __this_module */ const char this_mod[] = "__this_module"; - const int modname_size = MAX_PARAM_PREFIX_LEN + sizeof(this_mod) + 1; - char modname[modname_size + 1]; + char modname[MAX_PARAM_PREFIX_LEN + sizeof(this_mod) + 2]; unsigned long val; int n; - n = snprintf(modname, modname_size + 1, "%s:%s", module, this_mod); + n = snprintf(modname, sizeof(modname), "%s:%s", module, this_mod); - if (n > modname_size) + if (n > sizeof(modname) - 1) return false; val = module_kallsyms_lookup_name(modname);