From patchwork Wed Mar 7 05:46:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10263397 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 CFF73602C8 for ; Wed, 7 Mar 2018 05:46:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFAA12937B for ; Wed, 7 Mar 2018 05:46:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B37E82937F; Wed, 7 Mar 2018 05:46:27 +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, 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 DCCF42937B for ; Wed, 7 Mar 2018 05:46:26 +0000 (UTC) Received: (qmail 20060 invoked by uid 550); 7 Mar 2018 05:46:24 -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 19959 invoked from network); 7 Mar 2018 05:46:23 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=x5JfCzOkEunq/JJYivUAszT35eOQPYfrTlGPv5rCsOI=; b=HLJ0m/B2kf6Kka1IenDc1BkaRyCFoNNJjIeWSR8kIZsPmtTDYI1JLOL2V2rr9R4LNV LMpJWRHqNjHJ8mxnl3wBzYY0wRaNYkp99fctQkr9HY21Ft3iOXBAhAo41LTJ8P8zsMqs wyyq+egIjnsypPZD9zH1QXHCam/Oru2uEaCfA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=x5JfCzOkEunq/JJYivUAszT35eOQPYfrTlGPv5rCsOI=; b=PK/YL2veW+fslSfjF1z5sqjhFGyqvQwC5f+iWseirHAnIA2OM/NEw5FhaLpU9z3hFQ NRjS6jPvGttxW78fVd4mVlLNO0XC/XdIVMR8eahBt9Ojcw6PCGaE2PRiMyVZqNDPHHVr /OcT4qaG5tyZnLJZ7n69b7acAVMZUZSfb3TM5MP113ugSWXNxw+Th3x/yF5Wwfr33N1R MZ+XqD7hquUE/kAEnwFUwHCUMSOUSXgEc6gRTr8du5lYka1my/bv0ARTkT7w/zxV48Fy MQPB42kMq17RphAbOPxigTH2vpjokBE/7l45/XCk5jt9em2vRaypNtvyZ5XWPwmV8Xzm Ao2w== X-Gm-Message-State: APf1xPD6hdrXcwAe+aw+ry0MRetLiucTc1VrMd6xk6xZc8C3xMJbdIRn h0gZ5BxAiaEIpX0CB5UT/jeGeg== X-Google-Smtp-Source: AG47ELsKetWsKTOvWly08/7y0RBFms83sZ++MnQgLlWHA50xu29k3T6KxVonxRACz/pezljBNpx2Rw== X-Received: by 2002:a17:902:3283:: with SMTP id z3-v6mr19743745plb.118.1520401571723; Tue, 06 Mar 2018 21:46:11 -0800 (PST) Date: Tue, 6 Mar 2018 21:46:08 -0800 From: Kees Cook To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, "Tobin C. Harding" , Tycho Andersen , Oleg Drokin , Andreas Dilger , James Simmons , Greg Kroah-Hartman , Dmitry Eremin , Gargi Sharma , lustre-devel@lists.lustre.org, devel@driverdev.osuosl.org, Kernel Hardening Subject: [PATCH] staging: lustre: Remove VLA usage Message-ID: <20180307054608.GA9300@beast> MIME-Version: 1.0 Content-Disposition: inline X-Virus-Scanned: ClamAV using ClamSMTP The kernel would like to remove all VLA usage. This switches to a simple kasprintf() instead. Signed-off-by: Kees Cook Reviewed-by: Rasmus Villemoes --- drivers/staging/lustre/lustre/llite/xattr.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c index 532384c91447..aab4eab64289 100644 --- a/drivers/staging/lustre/lustre/llite/xattr.c +++ b/drivers/staging/lustre/lustre/llite/xattr.c @@ -87,7 +87,7 @@ ll_xattr_set_common(const struct xattr_handler *handler, const char *name, const void *value, size_t size, int flags) { - char fullname[strlen(handler->prefix) + strlen(name) + 1]; + char *fullname; struct ll_sb_info *sbi = ll_i2sbi(inode); struct ptlrpc_request *req = NULL; const char *pv = value; @@ -141,10 +141,13 @@ ll_xattr_set_common(const struct xattr_handler *handler, return -EPERM; } - sprintf(fullname, "%s%s\n", handler->prefix, name); + fullname = kasprintf(GFP_KERNEL, "%s%s\n", handler->prefix, name); + if (!fullname) + return -ENOMEM; rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), valid, fullname, pv, size, 0, flags, ll_i2suppgid(inode), &req); + kfree(fullname); if (rc) { if (rc == -EOPNOTSUPP && handler->flags == XATTR_USER_T) { LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n"); @@ -364,7 +367,7 @@ static int ll_xattr_get_common(const struct xattr_handler *handler, struct dentry *dentry, struct inode *inode, const char *name, void *buffer, size_t size) { - char fullname[strlen(handler->prefix) + strlen(name) + 1]; + char *fullname; struct ll_sb_info *sbi = ll_i2sbi(inode); #ifdef CONFIG_FS_POSIX_ACL struct ll_inode_info *lli = ll_i2info(inode); @@ -411,9 +414,13 @@ static int ll_xattr_get_common(const struct xattr_handler *handler, if (handler->flags == XATTR_ACL_DEFAULT_T && !S_ISDIR(inode->i_mode)) return -ENODATA; #endif - sprintf(fullname, "%s%s\n", handler->prefix, name); - return ll_xattr_list(inode, fullname, handler->flags, buffer, size, - OBD_MD_FLXATTR); + fullname = kasprintf(GFP_KERNEL, "%s%s\n", handler->prefix, name); + if (!fullname) + return -ENOMEM; + rc = ll_xattr_list(inode, fullname, handler->flags, buffer, size, + OBD_MD_FLXATTR); + kfree(fullname); + return rc; } static ssize_t ll_getxattr_lov(struct inode *inode, void *buf, size_t buf_size)