From patchwork Wed Apr 5 00:12:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9662751 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 5F71660352 for ; Wed, 5 Apr 2017 00:12:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52ACB20564 for ; Wed, 5 Apr 2017 00:12:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 476FC20952; Wed, 5 Apr 2017 00:12:19 +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 7CDB420564 for ; Wed, 5 Apr 2017 00:12:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752756AbdDEAMK (ORCPT ); Tue, 4 Apr 2017 20:12:10 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:33566 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751856AbdDEAMJ (ORCPT ); Tue, 4 Apr 2017 20:12:09 -0400 Received: by mail-pf0-f181.google.com with SMTP id s16so25545099pfs.0 for ; Tue, 04 Apr 2017 17:12:09 -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=hKqc5zS7B8sJW2wLkg0B6a4y+OcVXZd18xFSCX8ROUY=; b=a1JDK4VvQbFTzIQ3Ehx2/6C7TrxAavTIFOtrgvymsNVpiu/oe4y2F0cx3ad9NEPUl+ tIp8mrJBQCdQDBnIVcGddna46D3Ozj1cz0Y/aWQqNRMgIHAkqaK1HD3lMcsDBWx7zgYb iYbXeqvB3oDnmix1h72zti7F5/FW8TkjA2wXw= 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=hKqc5zS7B8sJW2wLkg0B6a4y+OcVXZd18xFSCX8ROUY=; b=nC4nigbsBja4TLHI+B/hKl2uw0u2Ropiy5DzuBU5qpnVQcsCxOTLDP1QFYjdb588KJ 6kfvJDv7nydsGY6xIvY6lgcp+cptDsNlqNMhCQhw4c7SogvyNOS0slkHPkDkSj7iKYUo DaCezvSa5YPIRqcrVF7VmwEzX/0lxR+LAW5G8iii8ORMzoowhVfVuuU4t3C0FnDne3sI LrQLyoD4M+HKT6lKx4lg+UIFml2N7pjN7gyt3eItN9GOaHbc5HGF5MBmik3jzsCIRF0w sYvecMZ57DV+TWfGRwjn+yZ+kRunJXJKSy5SuEff+NokX0eyZxCEJ5lGGcvNWzlB41l+ xRrg== X-Gm-Message-State: AFeK/H0/ZjHdyJbaxILVuWNdeqpBUDR3pghuWjX3Q4gnUH5mGEfc7/4Wu5P4usmqRwoeZswo X-Received: by 10.99.56.66 with SMTP id h2mr17964942pgn.40.1491351128543; Tue, 04 Apr 2017 17:12:08 -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 d1sm33715878pfk.20.2017.04.04.17.12.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 17:12:07 -0700 (PDT) Date: Tue, 4 Apr 2017 17:12:06 -0700 From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org Subject: [PATCH] NFS: Avoid cross-structure casting Message-ID: <20170405001206.GA58184@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 --- 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..89f50bf12f52 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_PTR(PTR_ERR(devname)); goto free_page; + } mnt = nfs_do_clone_mount(NFS_SB(dentry->d_sb), devname, &mountdata); free_page: free_page((unsigned long)page);