From patchwork Mon Oct 1 22:45:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10622873 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 54DE514BD for ; Mon, 1 Oct 2018 22:45:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45EA028627 for ; Mon, 1 Oct 2018 22:45:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A3902862D; Mon, 1 Oct 2018 22:45:31 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable 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 EC9F528627 for ; Mon, 1 Oct 2018 22:45:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726554AbeJBFZc (ORCPT ); Tue, 2 Oct 2018 01:25:32 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:35350 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725878AbeJBFZc (ORCPT ); Tue, 2 Oct 2018 01:25:32 -0400 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 w91Mhdwu095603; Mon, 1 Oct 2018 22:45:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2018-07-02; bh=35D4JCizLeOIYFxLqwL3VW3H7mvLOsL9se6kar0CUvY=; b=iRXgDuvIX8p2+CmdGrgBBcum7+mYdASGQF73WP5ux501FvI+tDsXP7Bqmx5/byRWMkFa gadlI4t8swfdzzxJsEOdsmZmdm3RW/FthFVuvVCS6/6u83VxoJSoVuIEk2OhxHAGjMiU f2iCwxLdD/nVRECalCQfO4lnLgBquq4GR+jANfQy2j2Oww42sSJM7jqdt4mmdAyzs+2o zYcn5GZoVgcS+gCkBrwvAZzfolz3U7lXnPxBMGvCeyfEgmcmhYVfZHDMi8Z9JwHU12xr NXTQLzjtz7cV4YHthxMx5TatSb839A+8eh60LMCRiOuFwoDY72m/MVBPpjkXMMPZCEnJ aw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2mt0ttjdyv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 01 Oct 2018 22:45:08 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w91Mj2NN015854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 1 Oct 2018 22:45:02 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w91Mj1I0032017; Mon, 1 Oct 2018 22:45:01 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 01 Oct 2018 15:45:01 -0700 Date: Mon, 1 Oct 2018 15:45:00 -0700 From: "Darrick J. Wong" To: viro@ZenIV.linux.org.uk Cc: xfs , linux-fsdevel , Christoph Hellwig Subject: [PATCH] vfs: check ->get_link return value Message-ID: <20181001224500.GE5872@magnolia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9033 signatures=668707 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=949 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810010217 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Teach callers of inode->i_op->get_link in the vfs code to check for a NULL return value and return an error status instead of blindly dereferencing the returned NULL pointer. Signed-off-by: Darrick J. Wong --- fs/namei.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/namei.c b/fs/namei.c index 0cab6494978c..0744ab981fa0 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4737,6 +4737,8 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen) if (IS_ERR(link)) return PTR_ERR(link); } + if (!link) + return -EUCLEAN; res = readlink_copy(buffer, buflen, link); do_delayed_call(&done); return res; @@ -4763,6 +4765,8 @@ const char *vfs_get_link(struct dentry *dentry, struct delayed_call *done) res = ERR_PTR(security_inode_readlink(dentry)); if (!res) res = inode->i_op->get_link(dentry, inode, done); + if (!res) + return ERR_PTR(-EUCLEAN); } return res; }