Received: by 10.213.65.68 with SMTP id h4csp110864imn; Fri, 30 Mar 2018 01:54:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+q3xDrAa+CnvlYBw2msXXiF+rMZ7tr7F8RQDo192I3+Kfz26DjKtA0wK5SUeyL0rf8KaZE X-Received: by 10.99.45.131 with SMTP id t125mr7807867pgt.267.1522400082537; Fri, 30 Mar 2018 01:54:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522400082; cv=none; d=google.com; s=arc-20160816; b=fYqXnEIq9/GjD4bLRj250UlEG7q/hV19XBZEu1Q1fQHWszHdB4xcL4dZccyno200+v zDgarGISUI53+v5++tNSKaQLl/lfG01A7fU8uG7ZD955DlcWxleA1tEWLpW8cvGO60GU bIf2qjS8a8nkioe8g48V/pFgSbot98kOfpazWJD7Z61xoWgE0yA0oQclk6idY3rMzTRz W3NQNVUKtJp35f0vJeVelAxsjbKHK/tTxskxfzD/JudptJyAzMB9W5KQj0/YhSjxm2s0 HjPFSXBAULiHS5EKN49CcEebBc6wFUjbnB2UuNhG/pPiupEkkZDmiPKLJyBjdT038S2F 4lKA== 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=qGnZyqfAqz97h1IJ1jKpe0mHDRkFqYwhjmIcLz/kaRs=; b=XochmFhkQ17VQz7T3qXcvSuyF4gEo9RM/StHm7rO4PaADQpUYSJbdna3Kh0yqB+hzr t55nebs5RciTfRCEs+Et62Bk47gmsfLv2ecS6i7eotNf1/+m/FJWoYNDDIqN4wCj9pig wFt8ev2XHlHkvXXN3atF4YRhkq5rbge7ViS4Yu6ognTzYYJluiebanZjVHpOqhP76FH1 sGGuIeW8r1PaZ0L4VpitRKDfHCjRHTyXtx9En1TSQlZOPoDzYhruTj4EjtRvsQg31xnJ PeW5ZQnRpYtj4MCg2uHCWw9W6NQnK23AxXysl6Cq1ZOg1Eume6ACzdYtX1nAL7RhjCI4 2ABg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OSmL0gPr; 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 u7si5877088pfm.15.2018.03.30.01.54.28; Fri, 30 Mar 2018 01:54:42 -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=OSmL0gPr; 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 S1751167AbeC3IxY (ORCPT + 99 others); Fri, 30 Mar 2018 04:53:24 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:55610 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750764AbeC3IxW (ORCPT ); Fri, 30 Mar 2018 04:53:22 -0400 Received: by mail-wm0-f67.google.com with SMTP id b127so13832957wmf.5 for ; Fri, 30 Mar 2018 01:53:21 -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=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=SbNON/GZg3VQ5ZAp2OtUvrao9jKpoyx0Kmu4ZY/IoPv8J9K5B9FnwHv9MyIz+PY0e4 29yF1C6pzEGEbDU0qGWHwpiKruC+cqCKzkJpyiosaGg23cRftL8JHUPxgvV5Zgx0qD+F X24tvz4/kZiz+QATgGppQ3CZS8MJQ2qtgrTlVY6zkPgDin4/4y/gBUMeDbt6PMgcerZJ MZ/bn7tyfbqGE98fwDSInOpY4O80FKv1R7rS4xVruh0F/7obI3fKMFyta1ZRp1tnf+kH KxUAfSgMn4lI3OCfhtPsp4/U4FfAkl5BJ4evS/AXRnoepi1WX40NI2yyW3OAL3kPnomn F2+Q== X-Gm-Message-State: AElRT7E8hv/mxWV3ofu5FZrd+rrNB4XqoW27oh7+OoVmdIuo/GXkDTKL Tw34w+mpIBjmoWAT8DsAcZfCSelF X-Received: by 10.28.116.20 with SMTP id p20mr1717717wmc.24.1522400000792; Fri, 30 Mar 2018 01:53:20 -0700 (PDT) Received: from localhost ([2.46.125.87]) by smtp.gmail.com with ESMTPSA id z16sm851508wrh.76.2018.03.30.01.53.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 1.9.1