Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp791131ybi; Fri, 31 May 2019 08:58:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqziYq5wJVvVEhe2kl68LwfECdtex9vTRKRe/aWW8ux4XPaWZzbHWEiYRFFt4tiXo8wLKo/E X-Received: by 2002:a17:90a:2268:: with SMTP id c95mr10322000pje.8.1559318312531; Fri, 31 May 2019 08:58:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559318312; cv=none; d=google.com; s=arc-20160816; b=mzAVSgB4Ii1eQl2y89esJyTA3VhLRqrjLxeJ3u9JEncR71xmKJOi5mmso3JNJxm9M+ aw7Ixobs6caAy3oiP19Q17FgG0UlzAM1oSia7sdKzK+NBFo7ppiBPaSJp8frEmQZxzWI wsjsS+6Q3rj3kioLbStRWoz3ML5+knlNfeM3KMPTaNu32PIArZdoEm2r5TeBmnFUXrZF orvw421EJxm6DwGvTT+BI6JuO61JvdbgUoN1YerrLQZO0A3JXW7Lpzavpw+l93sT6a5m 4lwBiHFuqU1dzOXcuWjeKOyQ9ge1bGcPYrQl22oMqClQGTOeheC28lJnfSxuUVO4k8bV /QEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=RVcOaYatOpeo1CRV+hYtc16/sImBcgmxdJUqU74IXf0=; b=PxX0t1V+cJ4m62TRbAQljS2Ftiv4bGc1fwWVWhEEM2n5RZc+5n7Uq7F4Dqrq+w32jv Q/8ty/tn0NYfz1WS/9Xc3GLBF2NVzw2WPz9oWo4jivFybGOLe8ofjddb3Eld1u3yhSmn sCdYhuaLwplXW6aSM2o4KwFB0c94k+ZK+pYFz98/N2eXcpR/YXOX6ueQqxPZGLQFLuk1 UYnZip5dwQXm2QRgXZRDZDMpaL6AOKSloKJuIxa1B8ErpzDJTcwmz0mjshemKOQIivo+ zAM0PaiTX4dx32au0hVk9A6V38WksPoTJqf8Yx5AU7ZWgfaod+wJRwZGWjb8bz2VuX2j 1ziA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=RPZh76mo; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o31si6186260pje.45.2019.05.31.08.58.16; Fri, 31 May 2019 08:58:32 -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=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=RPZh76mo; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727053AbfEaPzk (ORCPT + 99 others); Fri, 31 May 2019 11:55:40 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:41091 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727034AbfEaPzg (ORCPT ); Fri, 31 May 2019 11:55:36 -0400 Received: by mail-lj1-f194.google.com with SMTP id q16so10096875ljj.8 for ; Fri, 31 May 2019 08:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RVcOaYatOpeo1CRV+hYtc16/sImBcgmxdJUqU74IXf0=; b=RPZh76moKr55vlOhT6KnMQNS2x36jsAOlxZc9yNKyxBw0/CnSaJqQXxPo8wQogqSrH xvmcd8R/2F0tPP/2ihZ1+29FSCm9nEmo6aw5HY8bzked4RIQPKJuQOkb+A/GhtgtIj5a aLWdXP2tDDewNDPoZfQNbPfPMJRAtol/Hsyp/gqT51L1Anjn5GoDMPRjuY6Sc09LcwlO n4vSZg3ld4ZHB+BWhlysxicuNc0AlznR6JfJ4CZMe6EOFOQnF/TJRQYeJKzSXA7tqj9a Jpm9h6pr7EN7xwZSsvAaiJ12eb5JuE2TSUY+75Sh0GRQZQCe1qpwgP9inI/9WD2YWaC2 8PbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RVcOaYatOpeo1CRV+hYtc16/sImBcgmxdJUqU74IXf0=; b=WPIeSVOTX3g6IwUPARyIPQnhPlFA/06SyEJRUMcc3Noyu6ofoA/JVp+bc1+Akp3lHc kZH38sNV1NqdMS7WtvK2hUCSpfFk9i6xloDw6yjuDOwgVsHZzxVtK6U5qZMt7RmTTDkv vmH9btl24c6pCD1zb4k2vqIuaArR5EP14v/e9X5/eAErjkvNeEdvcwPQGcKj16VMp/wf c+WMhnmMcXpFg00FiVFlcEPwrExzNDvEZF9hdhRUjms0KwiN49VEE8KkcEmWOnrmHduX et0/5HkrGBIHNkZXYUFCm1C/VVvDA3s/QSpWFR0/uAdqVStvm6RjdDPfHgaT4uLvJZ6H qx6Q== X-Gm-Message-State: APjAAAV30EXV2oI+r1UPwUw4itNIijTiSp+uENu/2K8dk1BNyzjOPlWN 5AH14YfFxhSHZJt8+WYCVzDD5Ko29ARINoPKgHZd X-Received: by 2002:a2e:9a97:: with SMTP id p23mr6347647lji.160.1559318134012; Fri, 31 May 2019 08:55:34 -0700 (PDT) MIME-Version: 1.0 References: <20190530080602.GA3600@zhanggen-UX430UQ> <20190530085438.GA2862@zhanggen-UX430UQ> In-Reply-To: <20190530085438.GA2862@zhanggen-UX430UQ> From: Paul Moore Date: Fri, 31 May 2019 11:55:23 -0400 Message-ID: Subject: Re: [PATCH v2] hooks: fix a missing-check bug in selinux_add_mnt_opt() To: Gen Zhang Cc: Ondrej Mosnacek , Stephen Smalley , Eric Paris , ccross@android.com, selinux@vger.kernel.org, Linux kernel mailing list , netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > 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