Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp476506ybi; Thu, 30 May 2019 01:32:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIhNmDxvJOOsVVDQ27fi716TZ1V3D/je4Y7WdQO/eyPs150sJGEBQak7W+fNEVpxTuuNC7 X-Received: by 2002:a17:902:988a:: with SMTP id s10mr2658871plp.304.1559205127566; Thu, 30 May 2019 01:32:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559205127; cv=none; d=google.com; s=arc-20160816; b=z8mMHV99yNhDHfbOtKgUVJQdKxOgUZp4yNqwcbXXq+ooXluqlRMlcvpja2pCXdZsNB UlxrGPRPyt7nEETxDbfSUnAqUfd6Hpo8NN6Jq2XfLWU3Q1rL+lR6Bv2YCg1PmzWzAFZw p61dwIrt2Bahb6kSK9L4hQYZOlHlznTe8oRR4bg2DAXKLLvbn94A/FUY6kwEeLMun/cj g1pzMVS8ZP8kqILyl0gU80nreWz0kRAAneAjy+aFIDC6EG6Y9SfjFr1n0fZIYUpJEkmL Vr8FnzqpkaoaVqaTSYt9IwTKd/Zzzp6lTFO9h6sEJBDZ8Z6OAAcVsZcAQUCYIBJym3KK CN5g== 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; bh=vzcNV6SW+Xh9Ya8lDxl+0yI6Dw+WGyclNEKNTVCp8nU=; b=rY7ICgPB5Emm+5bSSY+oFXgyD2sWtBoL59w3wHWxn+0xEX1DhnJyaUx8JhogsH4x7b NWUbpB4GN4wjmPDq2k4ngW1ZW4Apr7Jci7I8vxjgCFR/PLbzqPsRzMpYHewer28IhF1I ZkKkBqvZb10GYetl0HOvSxU82K2XnPad4NVAFWD3pUAZzIVv4uxYgB0rIJnNZZ0YF9s8 Sm3OptW+3DlIXXs64qy6OTHX5pCxVivZLqm+kEoasONbKj4B2ETSqtFuUH7bWu5Vs9Tn +cdc1EqzpLzCYtcERFvTSSfvzQbtcWL9EbFxSzcJQq+36jTx4kbrwFciIS1Ht9EdS0Pr 56sg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gn11si2414691plb.119.2019.05.30.01.31.51; Thu, 30 May 2019 01:32:07 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726870AbfE3Ia0 (ORCPT + 99 others); Thu, 30 May 2019 04:30:26 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:41311 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726837AbfE3IaZ (ORCPT ); Thu, 30 May 2019 04:30:25 -0400 Received: by mail-oi1-f193.google.com with SMTP id b21so364432oic.8 for ; Thu, 30 May 2019 01:30:25 -0700 (PDT) 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=vzcNV6SW+Xh9Ya8lDxl+0yI6Dw+WGyclNEKNTVCp8nU=; b=oNY0itUuOlexInXW+Gp+VDdmTcz/v8A3OJ/ZmYzNmbNRg0nJUT/RP8nL+CggEXh6uu ILmKI3mWvUZdAsd0y9V6L1Xx/W0olFIAWtddBgV4yOGVkllOUxuSjKJ5ybW+0QFFNgnX KzwcGvKoTb+EWTpZA+njw+zF/xCbhXb4xfq0s2GwL49UzbvQb3WvnPM238KGDwncf1o1 Mr2yPy4Qu0nA4QMXNR9UAehZQFWWTrRTBcn7nEXdTU49ajov0AZgrB4c67uWQBTa/Q6i aJlWbafvPHV81ZKY4eSie5a+afJl9GF2BQyz24hdvv8mw+5WS9h7kKfp6ntyJtS+X19v zzMA== X-Gm-Message-State: APjAAAW2/ZuJFPgYNCNZbO0tE9koXbEGs5LogbZGUp3wYNwDGkZA1vxt 1NQeO8EhlPXkSQpEvexpnFZM3Ue6ULvnhUf+DkV7fA== X-Received: by 2002:aca:e887:: with SMTP id f129mr1752282oih.156.1559205024714; Thu, 30 May 2019 01:30:24 -0700 (PDT) MIME-Version: 1.0 References: <20190530080602.GA3600@zhanggen-UX430UQ> In-Reply-To: <20190530080602.GA3600@zhanggen-UX430UQ> From: Ondrej Mosnacek Date: Thu, 30 May 2019 10:30:17 +0200 Message-ID: Subject: Re: [PATCH] hooks: fix a missing-check bug in selinux_add_mnt_opt() To: Gen Zhang Cc: Paul Moore , 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 10:06 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 Please add a Fixes tag here, too: 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; There is one extra tab character in the above three lines ^^^ > + } > rc = selinux_add_opt(token, val, mnt_opts); > if (unlikely(rc)) { > kfree(val); Thanks, -- Ondrej Mosnacek Software Engineer, Security Technologies Red Hat, Inc.