Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp192605ybi; Fri, 7 Jun 2019 06:33:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+5aLlLrWJPYOuPQAPYMzpOqZSVZKjlYt9Ch4JsE4GnzRjg/pS49tNW3DEREiIMnM1j2GR X-Received: by 2002:aa7:82cd:: with SMTP id f13mr60139795pfn.203.1559914400767; Fri, 07 Jun 2019 06:33:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559914400; cv=none; d=google.com; s=arc-20160816; b=okYLnMpOCNEsUVrnY2PtcbesbFhjfet4nN49lJiqmySGfmJITA7f2tGPxigzkclx0F Co6cmNl+lcftz7ku4/43twkdaNFjfqX3coYqxllrRSH8k2IRDa4/KyJnOom8ReEq+Eu/ 10uUhqSQBsm2YBk9n8+HNQaZQFXoSkBC021cqDnKdDWkJp2i+D8BYkw8Y6OZCzctXqoi EHEJP9YjNx58EB6h5ezuU31amxQONKopphHAMBtYSRyHC4rx57vu8w5gN4FjpRWEgXmV KsA2MajbRpL1qFTXH3DRiiLWot4XimoXBfuApz/SzRg2yiGPoEMhNJhR8oI5E2fgAkv2 kZtA== 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=lCuMQSiPp3S50sfJ3MfqfVj+SodtoDh9nFJUhWW72Tg=; b=aleR16qJuLhj7bLXlpXuxegDEWYWdQPMvbuONcntTdzsPOScxhyHDgMvPg/i1vUWFm TiZl7gqE4NIWyZYpKUkEYJC14pZXgQ4Bg/GkvXFGtcQ2pAUhWdlbu6Mym5IVwdrafNxX sCRwQYiAIKqePBC/r1uaKZjAmnkvRTNkfhfoK993ryNhBAZwvCZtVQXNkMSPfnaOrV0I dAfBL+tvklMK6SvYNRBjMAM463VHMm0s1MceOn5yzhNZOu2PRS/t95MGD7nTpnFHVy9x oOolnvcnpOzO/EMQdDHDsc3V2l1i8pL2QALvrtqkG0Xleqz+WDkoSXsWKdCfjTkB0KT9 5VJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IOLcgTTf; 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 g17si1718801pgi.569.2019.06.07.06.33.02; Fri, 07 Jun 2019 06:33:20 -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=IOLcgTTf; 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 S1728287AbfFGMLv (ORCPT + 99 others); Fri, 7 Jun 2019 08:11:51 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50307 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727386AbfFGMLv (ORCPT ); Fri, 7 Jun 2019 08:11:51 -0400 Received: by mail-wm1-f67.google.com with SMTP id c66so1837515wmf.0; Fri, 07 Jun 2019 05:11:49 -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=lCuMQSiPp3S50sfJ3MfqfVj+SodtoDh9nFJUhWW72Tg=; b=IOLcgTTfVN1lKHhLQ8vgWF0dkmg15L/ybk7eFQJGBjBX8K2KWCOOr6YPVItt5AjZGj 9v1zObGANDZjucgKTkPASuG2daCtO/BnvVWwKhR/c1mKyseGOdAUSgY8xA3PIPwb4rVB 4upAtczueubzxODRbUY7vGA/r8YUK9yPyrpqWnMMFRMHGQOTL31SXoXcacFiVZkVuP/V QxQVkZlIN2xgjoTaHMvZ16MSyU2nmwxayRRIy38XueApqQIriCA4fFVnn/SQyg6S7BuV wwBKS45FuOM7eQngk821eUANQg5NaHATxitbsWv6BTNqcfhFp/etAjojy0JpxCQVWlOc HFSg== 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=lCuMQSiPp3S50sfJ3MfqfVj+SodtoDh9nFJUhWW72Tg=; b=DwYbi5TvUN4sQUoiI/ACGscpS2m6y0dGjwBhQvIK1yrxrmFs9tKnexLeE93XguEcls GxknrQ71YPLoLNoGl6dmjjwcj1X2BNJCeWj3Lq8kN1oq/ePpeCoVgt7dC/cdlBMDernf XAbs2SBKpc9uR6wp+3fsyNu7T0xawrSfzApogRPsV5mbmcW1OfAFJSDZr58tXDW59HgB YCwBd/AzC0nj1/2BEIjT+EbpR2RMidHR61Vouy/ByeEof6KpNEbis8GmrzMQ/XVs5A5/ 2kOFv5G0BVxxFpQdxzwUHlefkHPwZOrAhJ9ufLVJOJUz3Yp/c+eJjMy6NyKL9B+pF0YG C5og== X-Gm-Message-State: APjAAAWw20BU0ULXcZOGQzbR93klHputfKa69eTgbd+pxGuyYTuSNFZk +JezYcnGCpMQNqJyHb0494U= X-Received: by 2002:a1c:407:: with SMTP id 7mr3713361wme.113.1559909508107; Fri, 07 Jun 2019 05:11:48 -0700 (PDT) Received: from zhanggen-UX430UQ ([108.61.173.19]) by smtp.gmail.com with ESMTPSA id t6sm1972015wrp.14.2019.06.07.05.11.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 05:11:47 -0700 (PDT) Date: Fri, 7 Jun 2019 20:11:34 +0800 From: Gen Zhang To: Ondrej Mosnacek Cc: Paul Moore , Stephen Smalley , Eric Paris , selinux@vger.kernel.org, Linux kernel mailing list Subject: Re: [PATCH v3] selinux: lsm: fix a missing-check bug in selinux_add_mnt_opt( ) Message-ID: <20190607121134.GA3357@zhanggen-UX430UQ> References: <20190606092342.GA21672@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, Jun 07, 2019 at 10:39:05AM +0200, Ondrej Mosnacek wrote: > On Thu, Jun 6, 2019 at 11:23 AM Gen Zhang wrote: > > In selinux_add_mnt_opt(), 'val' is allocated by kmemdup_nul(). It returns > > NULL when fails. So 'val' should be checked. And 'mnt_opts' should be > > freed when error. > > > > Signed-off-by: Gen Zhang > > Fixes: 757cbe597fe8 ("LSM: new method: ->sb_add_mnt_opt()") > > --- > > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c > > index 3ec702c..4e4c1c6 100644 > > --- a/security/selinux/hooks.c > > +++ b/security/selinux/hooks.c > > @@ -1052,15 +1052,23 @@ 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) { > > + rc = -ENOMEM; > > + goto free_opt; > > + } > > + } > > rc = selinux_add_opt(token, val, mnt_opts); > > if (unlikely(rc)) { > > kfree(val); > > - if (*mnt_opts) { > > - selinux_free_mnt_opts(*mnt_opts); > > - *mnt_opts = NULL; > > - } > > + goto free_opt; > > + } > > + return rc; > > At this point rc is guaranteed to be 0, so you can just 'return 0' for > clarity. Also, I visually prefer an empty line between a return > statement and a goto label, but I'm not sure what is the > general/maintainer's preference. Am I supposed to revise and send a patch v4 for this, or let the maintainer do this? :-) Thanks Gen > > Also, you should drop the "lsm: " from the subject - it is redundant > and doesn't follow the SELinux convention. See `git log --oneline -- > security/selinux/` for what the subjects usually look like - mostly we > just go with "selinux: " (or "LSM: " when > the changes affect the shared LSM interface). Thanks for your comments. > > > +free_opt: > > + if (*mnt_opts) { > > + selinux_free_mnt_opts(*mnt_opts); > > + *mnt_opts = NULL; > > } > > return rc; > > } > > -- > Ondrej Mosnacek > Software Engineer, Security Technologies > Red Hat, Inc.