From patchwork Wed Apr 5 15:29:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9664501 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 9B05F60364 for ; Wed, 5 Apr 2017 15:31:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C4AA2855A for ; Wed, 5 Apr 2017 15:31:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 814EC2856D; Wed, 5 Apr 2017 15:31:28 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 0FB3D2856A for ; Wed, 5 Apr 2017 15:31:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755695AbdDEP32 (ORCPT ); Wed, 5 Apr 2017 11:29:28 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:33345 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754853AbdDEP3Q (ORCPT ); Wed, 5 Apr 2017 11:29:16 -0400 Received: by mail-pf0-f180.google.com with SMTP id s16so9066934pfs.0 for ; Wed, 05 Apr 2017 08:29:16 -0700 (PDT) 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=/dG6BA6XnF1RKumm8RbW8TqYF8ajioIcH6s1Kxot8Ig=; b=K2Y8zg4b1hSUohQmaxBxH8OFj4M6W/cRQex/xrsP58AF/98ZXbl53+OBDpQc9JyCyN 94NdggGDCjfOz6+E+GtxKbxu0q0zVcTDUtKhVITfl2P+oL0Z4gdipmitiTJSy2g0dMqe LFUxpoT8taXgE2TLhVvkJOzx/j0caOD0y8uw0= 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=/dG6BA6XnF1RKumm8RbW8TqYF8ajioIcH6s1Kxot8Ig=; b=Qx5ps4tLQqNGuxAZx/5PhgqlOTbDei+BhonX164iH9SwwrDYJyyGGif5UaKL3Xsk3J jDq3M9qpe2k3H9yfHiHzdNzxHsq0qL5fXrO2os4c2oxHYlqXQG0sEmEc+N2f04oA92b5 wSUp3gmZ71wnFio8ao5l3wmf8sHDE0jxl4RwrYX3fqRJFvBQRjxKWNvglkiK2tEPi7K+ 8EXxZcQCGpbA7yzm5+QCFaXnmSfFRIJBIifYPoHSG44kAukWaYy7PsY5+Sw6jL22j3dP 5YHa+Z+xjVZXnTxp2qr5USw9GAcOg015r2z5O5pNPmD4BLKIQBUVDDYuClvRG1kDlrmB RBuA== X-Gm-Message-State: AFeK/H03zI48PPGastEy4mE/09QOKTfmMrCdQUlFz87AaQfYolrqnyAvjUs5zuqKCncMsvLO X-Received: by 10.98.11.70 with SMTP id t67mr30136490pfi.259.1491406155872; Wed, 05 Apr 2017 08:29:15 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id q86sm10164851pfk.43.2017.04.05.08.29.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 08:29:15 -0700 (PDT) Date: Wed, 5 Apr 2017 08:29:14 -0700 From: Kees Cook To: linux-kernel@vger.kernel.org Cc: NeilBrown , Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org Subject: [PATCH v2] NFS: Avoid cross-structure casting Message-ID: <20170405152914.GA57260@beast> MIME-Version: 1.0 Content-Disposition: inline Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the call to nfs_devname() fails, the error path attempts to retain the error via the mnt variable, but this requires a cast across very different types (char * to struct vfsmount *), which the upcoming structure layout randomization plugin flags as being potentially dangerous in the face of randomization. This is a false positive, but what this code actually wants to do is retain the error value, so this patch explicitly sets it, instead of using what seems to be an unexpected cast. Signed-off-by: Kees Cook Acked-by: Trond Myklebust --- v2: duh, use ERR_CAST. thanks neilb! --- fs/nfs/namespace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c index 786f17580582..8ca5d147124d 100644 --- a/fs/nfs/namespace.c +++ b/fs/nfs/namespace.c @@ -259,9 +259,10 @@ struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh, if (page == NULL) goto out; devname = nfs_devname(dentry, page, PAGE_SIZE); - mnt = (struct vfsmount *)devname; - if (IS_ERR(devname)) + if (IS_ERR(devname)) { + mnt = ERR_CAST(devname); goto free_page; + } mnt = nfs_do_clone_mount(NFS_SB(dentry->d_sb), devname, &mountdata); free_page: free_page((unsigned long)page);