Received: by 10.223.185.116 with SMTP id b49csp6164485wrg; Thu, 8 Mar 2018 02:58:21 -0800 (PST) X-Google-Smtp-Source: AG47ELtsgjPChQ2zmAgGKZupQvnk6dMxoXlIIFngaLFFK/G7EsV+ae8SqrfxYzGDS+AyxzWlMgTf X-Received: by 2002:a17:902:183:: with SMTP id b3-v6mr23443947plb.80.1520506701469; Thu, 08 Mar 2018 02:58:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520506701; cv=none; d=google.com; s=arc-20160816; b=09NpoL5avKFTm2cjjPpxwbc54sWYjp5c5sTehoa96eGfGjjCLnrHPK8JI7h6eA4f5y Qm5E+Poaag2lor3tFxW/MiYvTeNj9cg3UzPUXYihZa8KEwnc0m4pZlhGa476E2Ga8eeM BW8/yagqSmSzpCqD0hy3DJCmoH+mD+m+pG+0//jRpEU3OhtOZDtXnsK3WgMf0b4leXit +2rtXulFIZepLdlXGZ/AsWOHKv02sgs2dDerjm7DlAyIcmPf4oKd5LebsOygzyE2kT6E fVrf788UM64Q3xelG06/5OxYaJFWCIe+3U8GnMFN4v4i3pB+z3E3Cg4m6fVDd6JF1byi poVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=0dhwsOxEz0w5msUTzHB6GjkgZTTDAHS7qjlAWWvEsCE=; b=zA+RZ4MaR4GsXWqy/g0ssyFgiVx8FGcwe7NtsXfF9z527wbvtrj8yGDC6Mer4SXgjZ wHv+xMsIMnMD3wGqI8udu9T6dmaOd9EfMZoywgBEwil8VIauk8zSQLm8hESrJI/fBu01 TNTRdmyLWMWW8zXmE9aCHd7xAYnXWWS59Z0VOM2XpuTvTQIKq9uCi26htFYYubnjRQAX Vp8DxnoAX6Q6t6tvJIF5S3+fYZex3vG3qGrsgdpmtqryvMTrZLP7jn6ruT0pHodoeo/x sm3qZHhBXkH4zwB9Chab7nIN6YRJpX6CaZOVVViM1jZslQQogd2mFQxboO9uDuu0+9ta OF2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=YSoB6VG1; 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=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j186si12641089pge.747.2018.03.08.02.58.06; Thu, 08 Mar 2018 02:58:21 -0800 (PST) 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=@oracle.com header.s=corp-2017-10-26 header.b=YSoB6VG1; 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=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755105AbeCHK44 (ORCPT + 99 others); Thu, 8 Mar 2018 05:56:56 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:44770 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751622AbeCHK4y (ORCPT ); Thu, 8 Mar 2018 05:56:54 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w28AjBuh039812; Thu, 8 Mar 2018 10:56:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=0dhwsOxEz0w5msUTzHB6GjkgZTTDAHS7qjlAWWvEsCE=; b=YSoB6VG1zgmcCOGmLzTa2UStfx9Anewxci7iiyf/uazrIeQQsK9mpWKxF9l1Jq0JfvG3 Ug9XnsAwfhRn7tITtTgkin+J8Unxs5W+tTpUDEv6nXlBmkxKSEkNa3hSJ745xn3/KB2Z d+/nhGexOYeb31BlLsRg7C2SuLV6K1NunRhZWuudKZHnf4opb9At6bRP7cFmUnZ+21hK QCvh3geYGFj50cybGOfZFoeQNgYSI9bVNsHXj5q6oA3IudfXQDnY5oNMiORPmL9F/zk1 eI18jUg//pJSlWY5vhfTRYWOkYA/oyQaJBHX57z8N5o7V7LYUN2IwNkax9ZA3vp1t1xy CQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2gk3ppr30p-180 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Mar 2018 10:56:24 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w28AhLox020549 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Mar 2018 10:43:22 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w28AhJhw012447; Thu, 8 Mar 2018 10:43:19 GMT Received: from mwanda (/197.254.35.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 08 Mar 2018 02:43:18 -0800 Date: Thu, 8 Mar 2018 13:43:09 +0300 From: Dan Carpenter To: Rasmus Villemoes Cc: Kees Cook , Greg Kroah-Hartman , devel@driverdev.osuosl.org, Dmitry Eremin , Tycho Andersen , Kernel Hardening , linux-kernel@vger.kernel.org, Gargi Sharma , Oleg Drokin , Andreas Dilger , lustre-devel@lists.lustre.org Subject: Re: [PATCH] staging: lustre: Remove VLA usage Message-ID: <20180308104309.l3j2deqrgq5d472g@mwanda> References: <20180307054608.GA9300@beast> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8825 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803080130 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 07, 2018 at 02:10:41PM +0100, Rasmus Villemoes wrote: > On 2018-03-07 06:46, Kees Cook wrote: > > The kernel would like to remove all VLA usage. This switches to a > > simple kasprintf() instead. > > > > Signed-off-by: Kees Cook > > --- > > 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); > > It's probably worth pointing out that this actually fixes an > unconditional buffer overflow: fullname only has room for the two > strings and the '\n', but vsnprintf() is told that the buffer has > infinite size (well, INT_MAX), so there should be plenty of room to > append the '\0' after the '\n'. > > > + 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); > > Same here. > > I'm a little surprised this hasn't been caugt by static analysis, I > thought gcc/coverity/smatch/whatnot had gotten pretty good at computing > the size of the output generated by a given format string with "known" > arguments and comparing to the size of the output buffer. Though of > course it does require the tool to be able to do symbolic manipulations, > in this case realizing that > > outsize == strlen(x)+strlen(y)+1+1 > bufsize == strlen(x)+strlen(y)+1 That kind of symbolic manipulation is crazy hard to do. regards, dan carpenter