Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp497569ybi; Thu, 30 May 2019 01:58:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOBoejbYuWRh+JJhbvOra8c1zbu1yRyq5a9zXn1sjLdcSyGG7ku2QZ1t7Rzo29LF2ecMPL X-Received: by 2002:a63:1a5e:: with SMTP id a30mr2648210pgm.433.1559206681390; Thu, 30 May 2019 01:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559206681; cv=none; d=google.com; s=arc-20160816; b=UP/+cnlu43aity8AmxEnHCEKYVVtaG0Ot76RjDXRELzrxgkOYLOjLWXRn0kdO3V+Pj mCq9zGU1bnX4vtCYff3HNaH2LfCEHVtgUh7vp7VQFRtERXWyDw7l7pmaW8PDtZIQyODF EJQKX03km5lRQ4bwNJA67g51xWmPpWHpJmwX/rUpMnFsKiTxXU7Ici3kO8mFBYM6cGgm wjtuQQBT2oOeNkfhWqYXeKAarKGTsRltEQsYMrZ5htJRIP3wLueS/Ym0Eaq9+6Ih+z09 +XNEc7bz3D8wXz1cD/TUq2qedSe9zau1cPMRAZqKsD5oC5GBuHleKuGEVO/6bNrgaCI3 /mhQ== 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=KvjM4bsTfrcq2cHYj0Oc8PDr1CJFW5mpcAz8/WiY3E0=; b=Rpng76LwdlLS27zIz1OvUc1Bo+X3+NWXZG6DolY4O+Uw2pGEKd3sg3yPoNDNtJxFzJ zugnWrz9g9Av5xO9ftjU1TwTrDiJedCFz9dUolN1z8pGcM/4lAn1DH5FEqUdDRAiMViH 4dD3xqkEk9nXoIgAHhxENtyzxbPBiD6YgQwTLG3GxLGiENMp59aEUy2ep3Xx+/jtlYVM VKPuIVGpvs9PdhHgnhJD186J0vLmm2kCCEYyrilqNp+eXJqgWzvkjoIKrc3e4yX9z1Kt Gi0G146j5w04KjDW35qyFEVtcWMpz1s7+YuI7NF+7Q8M2Z+KGOGEB+Iv6HTBV1j5RKto P7jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PJIRhFYa; 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 s71si2502865pjc.10.2019.05.30.01.57.46; Thu, 30 May 2019 01:58:01 -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=PJIRhFYa; 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 S1727307AbfE3IzP (ORCPT + 99 others); Thu, 30 May 2019 04:55:15 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:44648 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726653AbfE3IzN (ORCPT ); Thu, 30 May 2019 04:55:13 -0400 Received: by mail-pl1-f194.google.com with SMTP id c5so2274871pll.11; Thu, 30 May 2019 01:55:13 -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=KvjM4bsTfrcq2cHYj0Oc8PDr1CJFW5mpcAz8/WiY3E0=; b=PJIRhFYa2F4McFzf+xGE3gUTho75opN9ktQ1NXCUdCcGydnK/sgVU70hxfve2x1Om4 y7lXw5PIyHReB38bZ9+AUHhktIyjgnChQ1AXedGWj9Iwsd4CH+wIcTPLIovd3faUjsFP 1/NFvpt8TeW6wPHTiPHSQftQHiNxAGSVvR0mn2DfIEfNNIc5LcWfkblavemxfWL+ETP+ mT7HFpTnW3wrY5Re/8uPNraDblHqA3cuWX1OYHHYuH7ferAoRnqP7p3DhZjOVoy7eu3R qjwSINqsn2QOGRvm48tJuDzLp18JlNJja60GkZ5u3oe8eyI6/jP2dnLtGMuypw8YhldW ITMA== 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=KvjM4bsTfrcq2cHYj0Oc8PDr1CJFW5mpcAz8/WiY3E0=; b=mFuPBaZ8Bvl/S7hzfUnehpx6k667wUS6GWFsx4H5ouyUEB+lTEZYeL9+TCP1m7FO5g xRvdGsJepV1hhCs3dz/J3VRoEc4wDj2LpKbN075XbsQbUZ7ylHoGlbZ01ZwL7mPcwAnf CQJH4R1ExeFnZby+T7HWq075czI9ElY1xCcSzxa4qaAxmY2kvdC7lHpjz1bO75esSkl0 eJA6WkwSb5HmsL+HZ8V4qWUuP3IeS7lFHM+LqzicwUMwlNArhi9RhNxnMsX9rEzEGwUu yUDvB/iEOBhUYG4TcHohiDyDz50SFT7I9P2ORC9IOZ5HQ76M8OTD8eoWfQ5G1K3c/qDm BnbQ== X-Gm-Message-State: APjAAAWTk9j5tVC1j/ZMIV1UwjwhY0b7S3yyBFM/OppUzLevj0OzQYu2 zZGmmmvjLZs4j5dd08sXy8M= X-Received: by 2002:a17:902:324:: with SMTP id 33mr2735283pld.284.1559206513206; Thu, 30 May 2019 01:55:13 -0700 (PDT) Received: from zhanggen-UX430UQ ([66.42.35.75]) by smtp.gmail.com with ESMTPSA id o15sm921189pfh.53.2019.05.30.01.54.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 May 2019 01:55:12 -0700 (PDT) Date: Thu, 30 May 2019 16:54:38 +0800 From: Gen Zhang To: Ondrej Mosnacek Cc: Paul Moore , Stephen Smalley , Eric Paris , ccross@android.com, selinux@vger.kernel.org, Linux kernel mailing list , netdev@vger.kernel.org Subject: [PATCH v2] hooks: fix a missing-check bug in selinux_add_mnt_opt() Message-ID: <20190530085438.GA2862@zhanggen-UX430UQ> References: <20190530080602.GA3600@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 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()") --- 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; + } rc = selinux_add_opt(token, val, mnt_opts); if (unlikely(rc)) { kfree(val);