Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1347952ybi; Fri, 31 May 2019 18:59:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqw67dYKRbPUxCg79qxfHorIrOBrbqEGvMwxxDfseImbZr15BSs1HJCyO2Ix8oVhANg6Cu0D X-Received: by 2002:a62:1a0f:: with SMTP id a15mr14527300pfa.111.1559354376538; Fri, 31 May 2019 18:59:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559354376; cv=none; d=google.com; s=arc-20160816; b=wQjayGdCeP2QgQ4WWeSWupX3zRJzuCIM4yROsaSK9YI54YIHCPBIRswyO1JjzWGz1n rx8Uh/9x5Co9yE1I89YnwkV45RYXGIL8U0PFwCIbCF4dARVELoH9izN2Nijxfo5FGmLF gBuFJ6yfxobfzHgshIDz/Lf3nbufoRGzVNGCBO3N6FWoC8PPefl2bNWEVUkpda47hab8 VFdoAFxnpokDeKYdHydhYqL3+LK7sCt+txnr49Ws7XOxI+Pv1gZYiX7zKcVZmIWL8FrK UQBsPXSu60nSzK2qvqd3Djx3olioHvUNjEUpkPpBnG/cMzNghmSlcLHfokeN9MDwTOT2 laKA== 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; bh=uS+vkMtqLwlIIErU0XBgxFsO/mgm3Z3e/UEBQvk7P8o=; b=qUEfvbBQok4F8G9v8Ko2ioTiT5DxgOxeidyxLHiElK52wTcWWVX26hR92hTcPbMy7Z i70VvfGOCz+2KeFs4lRb9A3KeW5upwUzHQMknJl6rhr8k8tWQRgyHzaD5yn7JrfDtP7U YezlDSCRRgxQkBIZYs/t8+959ESFDP0SX/w9QsHr6ov0DmVPkzMB6phqrnzjEMGZbbob c5F9S33l8TfudjYfbML8u5RzfElrgGnzvA9lEWiSJFQqwybhT5e3zY9ce17qZdJrhhqp qFtbVB6l7GHOenRqLrNyosoGmTjKJlLdRoKSckW3qnLi0f3+B0/wOlzJrHGV4CsALzOe sYag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="SLIlcpF/"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si8439389pfp.288.2019.05.31.18.58.44; Fri, 31 May 2019 18:59:36 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b="SLIlcpF/"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727056AbfFABy7 (ORCPT + 99 others); Fri, 31 May 2019 21:54:59 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37128 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726881AbfFABy7 (ORCPT ); Fri, 31 May 2019 21:54:59 -0400 Received: by mail-pl1-f195.google.com with SMTP id e7so4210959pln.4; Fri, 31 May 2019 18:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=uS+vkMtqLwlIIErU0XBgxFsO/mgm3Z3e/UEBQvk7P8o=; b=SLIlcpF/RkF/lfru9fMPLVo34LGp6B4XeEx1g4Lg4HJtqxO5Aja6HUn9uQgx611RkX isnsTKvJMlYVOCP4kwvm+HPblCUpsvNA7wRaWwxqkxVKpB2X23uSoMuXlByZv/Hct1TG aT9nqdC/bcDgcIPQHQ2tqJcXYY7gkersU7cC76wvqiS6aIuHmkXCCCx+blwCixi2NUA/ HMPT2W+zvwZXbJ7HNP13J41zO4SGnt9YSzGbdlbp66sUmYEF892q3DsWenZVebCNt4dL vBAk0h2oupbJyLwf7LBwoNlNS2gIryySrMebXuAGW/T3FYbcqMhuAUVlEjocVS1Ivt/C yPOg== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=uS+vkMtqLwlIIErU0XBgxFsO/mgm3Z3e/UEBQvk7P8o=; b=ZUca1MxvksfElbArQMceZEgL0pEaM+r/pKNXuveDUaeMBuZNTpz9zfLnynk4yeadfc A8snaqj8Oghbw7CO6aYIDGVHd/9lmNka5Lsb88SJohMwOAv7Uvvvr0/7R8bj6AiPJ/Zs kReC3PVD4+RihBgpFDTYmtqN5XqJ7v6RGK8qGOc4dldniEnp4ezDRAUrYEgHuROxveqf dJwYAm4rr/uh6UMOtKFBbk4wN8EJnjxMnE0wvY0imknAZPQoaD8HHjFofzJulXClLNth cmwB8+obDcYknfeInzrd8RcUsF+C92N4UqVfM/+oqNGJ+boWsTYQBK/rv1f0cUiAWfxB hIBA== X-Gm-Message-State: APjAAAX93JclN/enxHDNeiYj5dIoXSvXqJDpm5uJyXDv8Fq6t0oeyAWu CFA5BgwB2yWAcqT575UAU94= X-Received: by 2002:a17:902:205:: with SMTP id 5mr12386264plc.165.1559354098463; Fri, 31 May 2019 18:54:58 -0700 (PDT) Received: from zhanggen-UX430UQ ([66.42.35.75]) by smtp.gmail.com with ESMTPSA id y16sm12198928pfo.133.2019.05.31.18.54.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 May 2019 18:54:57 -0700 (PDT) Date: Sat, 1 Jun 2019 09:54:42 +0800 From: Gen Zhang To: Paul Moore Cc: Ondrej Mosnacek , Stephen Smalley , Eric Paris , ccross@android.com, selinux@vger.kernel.org, Linux kernel mailing list , netdev@vger.kernel.org Subject: Re: [PATCH v2] hooks: fix a missing-check bug in selinux_add_mnt_opt() Message-ID: <20190601015442.GA7832@zhanggen-UX430UQ> References: <20190530080602.GA3600@zhanggen-UX430UQ> <20190530085438.GA2862@zhanggen-UX430UQ> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 31, 2019 at 11:55:23AM -0400, Paul Moore wrote: > On Thu, May 30, 2019 at 4:55 AM Gen Zhang wrote: > > > > In selinux_add_mnt_opt(), 'val' is allcoted by kmemdup_nul(). It returns > > NULL when fails. So 'val' should be checked. > > > > Signed-off-by: Gen Zhang > > Fixes: 757cbe597fe8 ("LSM: new method: ->sb_add_mnt_opt()") > > Previous comments regarding "selinux:" instead of "hooks:" apply here as well. > Thanks for your comments, Paul. I will make some changes. > > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c > > index 3ec702c..4797c63 100644 > > --- a/security/selinux/hooks.c > > +++ b/security/selinux/hooks.c > > @@ -1052,8 +1052,11 @@ static int selinux_add_mnt_opt(const char *option, const char *val, int len, > > if (token == Opt_error) > > return -EINVAL; > > > > - if (token != Opt_seclabel) > > - val = kmemdup_nul(val, len, GFP_KERNEL); > > + if (token != Opt_seclabel) { > > + val = kmemdup_nul(val, len, GFP_KERNEL); > > + if (!val) > > + return -ENOMEM; > > It looks like this code is only ever called by NFS, which will > eventually clean up mnt_opts via security_free_mnt_opts(), but since > the selinux_add_opt() error handler below cleans up mnt_opts it might > be safer to do the same here in case this function is called multiple > times to add multiple options. > > > + } > > rc = selinux_add_opt(token, val, mnt_opts); > > if (unlikely(rc)) { > > kfree(val); > > -- > paul moore > www.paul-moore.com Thanks Gen