Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3011597ybi; Mon, 17 Jun 2019 14:39:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzkOaOCDCRDOMlD3hq6LpX28/e+a5hMV1Fg+vwveeJkGPpunXHrHLVKqwOuGSVqIq+WK1c X-Received: by 2002:a17:90a:9382:: with SMTP id q2mr1201330pjo.131.1560807542411; Mon, 17 Jun 2019 14:39:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560807542; cv=none; d=google.com; s=arc-20160816; b=GUOWf6ig1QNyZoLEpnqAwOBwRP+z+RQ0ROq/0NtEKoSgzgQzVwGElPj18JJDLOk4wo PKGyXhfKZVCreSf2cdoF1fAM+X+gjONvqvUWULXT0lfiPaDG86IIdmks41D0Q71vGRlN 9tq5UCS3lc08oWleXcO7EDknltusa2CYlqANIBW++DFTvEir1QmqS761bq8ZLSNU4YtY 43qlhZ5bdhfgQU0MrpXjNuVszE5UQSGfkX9s/S8fSpi8SaEX6sSEryH0n9FBzl4wfVcD f/hGxgMK0zecscjzp1CSnDvo1Wx3BRhELqMuhjeyW0UeTqii/eptqMrcIULJAZvwTeaJ zm8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=y/Te+fTq6ybXTfMRh9BeZ5oCcrAgxgeBj78RzdFZH3s=; b=ck7s8dWCnEww7N7+01ibnuZIVjl3a8T4w9f96xs9NpQIjFXcueh7UkjuNG1JCuuWHh nmCtQimZNorjeNoWoYEQXZK4VZqQPH4g/P9UfC1l2RNHoX2G8asmdPNdYDnRNvF/2Xr+ VNmf9BMuoAuFAEV8LvZmP1erP4tIGtvo9EHx8ewvnA2jQ1eVN39HJml6gCPq/QIEuVKH mGBKwi0gC6giHtwMTo6DJjDEj2AHGBXfIK3LS8TGbo9HzhZfTCIxM1i60g6KlJeL1PZM 2ObJYRVfFiEXPRGLwPArYDZ2Rch09QCqEA2oISAJz7rFZfZnq2PXhDJcBx6R8pllBeIi Xgnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zR+nEQGZ; 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 y4si10681027plk.357.2019.06.17.14.38.46; Mon, 17 Jun 2019 14:39:02 -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=@kernel.org header.s=default header.b=zR+nEQGZ; 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 S1728689AbfFQVTI (ORCPT + 99 others); Mon, 17 Jun 2019 17:19:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:42612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728555AbfFQVTB (ORCPT ); Mon, 17 Jun 2019 17:19:01 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 989DB2089E; Mon, 17 Jun 2019 21:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806340; bh=rlODXlwcieK5G7VrkLfAk+yjUpoAtfbVZYrEhVic2EM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zR+nEQGZcTahb1sTi5GspU9xExELuYRUO7QdKq04UP6fEfD5f8YfszsBrgwUh22tN s8qBVn22cKLylOiKHlFmOQ4vpHC6SAIjfkpTYZ1fgzQKvgf7wp5Fl0ty27GFIhvbUG RFCxJkLXcBbnjEtWbTr4YEMeJFyFEguTLK7rnPPk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gen Zhang , Paul Moore Subject: [PATCH 5.1 019/115] selinux: fix a missing-check bug in selinux_sb_eat_lsm_opts() Date: Mon, 17 Jun 2019 23:08:39 +0200 Message-Id: <20190617210800.895511185@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210759.929316339@linuxfoundation.org> References: <20190617210759.929316339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gen Zhang commit fec6375320c6399c708fa9801f8cfbf950fee623 upstream. In selinux_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul(). It returns NULL when fails. So 'arg' should be checked. And 'mnt_opts' should be freed when error. Signed-off-by: Gen Zhang Fixes: 99dbbb593fe6 ("selinux: rewrite selinux_sb_eat_lsm_opts()") Cc: Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/hooks.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2612,10 +2612,11 @@ static int selinux_sb_eat_lsm_opts(char char *from = options; char *to = options; bool first = true; + int rc; while (1) { int len = opt_len(from); - int token, rc; + int token; char *arg = NULL; token = match_opt_prefix(from, len, &arg); @@ -2631,15 +2632,15 @@ static int selinux_sb_eat_lsm_opts(char *q++ = c; } arg = kmemdup_nul(arg, q - arg, GFP_KERNEL); + if (!arg) { + rc = -ENOMEM; + goto free_opt; + } } rc = selinux_add_opt(token, arg, mnt_opts); if (unlikely(rc)) { kfree(arg); - if (*mnt_opts) { - selinux_free_mnt_opts(*mnt_opts); - *mnt_opts = NULL; - } - return rc; + goto free_opt; } } else { if (!first) { // copy with preceding comma @@ -2657,6 +2658,13 @@ static int selinux_sb_eat_lsm_opts(char } *to = '\0'; return 0; + +free_opt: + if (*mnt_opts) { + selinux_free_mnt_opts(*mnt_opts); + *mnt_opts = NULL; + } + return rc; } static int selinux_sb_remount(struct super_block *sb, void *mnt_opts)