Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8831266ybi; Tue, 23 Jul 2019 16:15:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqlnzd3HZe/OwZPw63QO8O0hLCHDuwYzQsDaPGWnmK579PMdBE+B9Z40lsstNmcOqAtW4O X-Received: by 2002:a62:1807:: with SMTP id 7mr7974326pfy.149.1563923709333; Tue, 23 Jul 2019 16:15:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563923709; cv=none; d=google.com; s=arc-20160816; b=Qx6JJYfvbHnlSlVQGilVZOvUNrgIdMkRIDX4l4sXVo0adOy0ro3ZQVPMT0CHZKThV5 e99KUxto3D9ncn9+2xmBX4dLRf33hxPFeM1jHgF6xy8maV/ACLRPHSFnslLOm/quK5x6 nCv+CjbylmUH/NLUZYFDd9bt1w8qRrcJTIlW36K0xEcCM/y8nB4j/tqZyERC6laaPIML 2+tqkDvn4AZnkhsoFDQfkanqvi+PfClHfzGJfxp6VvphZmOgvXOrlQnBrpl8OkSXS8Qc V68tIfvGqRRxsmYk6fh+z6yBB5yDBDT7q1QYHmKO9Dsqos+swDzMPioSqvRIoQ5VJANh PVZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=ScN8WzRMKv9ujMKagsG6pPThL/4YrWzQ0Mh2lGU8I9Q=; b=T74MRRfRDSNS5qHF/IkQ3folXLOBL33rw4L0r9KoCdbsV4tQpgaMZ1Dk5+2N/ZIiFa ygVIFQk186dTpIhdidOdq3xbo2yyNw/rNVDCmp+PGqT5xLQxN4yWZsmurSH1hJla0od4 VrfMgU230R82MX6P/8shizv0bAYT8CbvNkNy6jo7XSVftQjrIFCFE99QjfeNVSYr+Ftv cP2mdV4RANGT7l5thVinHuc4ZabugfMxkA6q021L9JYMbSKXzTI2cCiTq6joTgQokA7j 39sUXXFDf3o4FCYvgbOCqdKtiWTHfnvxRgR1OwhHW+qoIS9kLvDHKqPs5alz/odsE5eZ 6Nxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TSyIOGxI; 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 f61si11720999plf.258.2019.07.23.16.14.53; Tue, 23 Jul 2019 16:15:09 -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=TSyIOGxI; 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 S2389753AbfGWMuB (ORCPT + 99 others); Tue, 23 Jul 2019 08:50:01 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40944 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726107AbfGWMuB (ORCPT ); Tue, 23 Jul 2019 08:50:01 -0400 Received: by mail-pf1-f194.google.com with SMTP id p184so19094392pfp.7 for ; Tue, 23 Jul 2019 05:50:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ScN8WzRMKv9ujMKagsG6pPThL/4YrWzQ0Mh2lGU8I9Q=; b=TSyIOGxIgaDKwv/VxCj9bFdSyEYkKmwRWtQYccafT2FZwvSVPVcwGy9p6YB3jYyvfE IeYF5PtZPvSwA/3F6zkI8ozhCAqW8aWMETFoQu8cRdcCNYvdZCXrki5P2bKeogpqBf1U WMbprsYbetR4G+JcREVUCLaDKpwNV683KXqQjMVypckUH0XsUeWzZmjF92kDBtefSYzV pqwB917WJ7+yZsTh8QnRa9ZYQCRByw9Z3GBy9V58gi2Rk3qUvUosmftkhYzYmXk5taoN Dn4Cu3sHOB1KHX5a6R+ensmxSRb8PpYckJXntTO3mH+0JCiq2XsT7/my9jVxTIJo1f6L FXlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ScN8WzRMKv9ujMKagsG6pPThL/4YrWzQ0Mh2lGU8I9Q=; b=QeCedJmevMijKN7VOJxIxsn9vZ3gIZQyfTwt3tn7XWR5247dAllUjYUgPnLJTSk1HK igzqmZCGJEL0F6CCDFKJ2sp8quncbDcZDcAPa+qYcb1qJDiBpq3fOJWVy961NqQUzJuh hW/4DLBsCctpGUZR4osp+usGtW0uxFFszbi6QzuWmKSuOv/6lFjo4wbE0eIbtN6n5Vuw LqcHf+YyY94g8Xf4bn85FZ05fKkTwFKKCgnvd7P/5YRn/vc4gUFz/bZ1GfWCzG7hMQw1 64MkTU4Do4mfp0FaINuVzKP5PjYUyTyzcw6YAAnCCQUiei061R6hZSUdUBKJzNb56IAd E90g== X-Gm-Message-State: APjAAAV6J9xkitD7u8H9wGvh73GNLB7KYM4zhjAiS1xtYxHh5pdqt5iZ mIw0oO92r6jV5S8VA4u26Cs= X-Received: by 2002:a62:4e58:: with SMTP id c85mr5635177pfb.176.1563886200947; Tue, 23 Jul 2019 05:50:00 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:4:72:808::3ca]) by smtp.gmail.com with ESMTPSA id e17sm33750479pgm.21.2019.07.23.05.49.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jul 2019 05:50:00 -0700 (PDT) From: Jia-Ju Bai To: paul@paul-moore.com, eparis@redhat.com Cc: linux-audit@redhat.com, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] kernel: auditfilter: Fix a possible null-pointer dereference in audit_watch_path() Date: Tue, 23 Jul 2019 20:49:51 +0800 Message-Id: <20190723124951.25713-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In audit_find_rule(), there is an if statement on line 894 to check whether entry->rule.watch is NULL: else if (entry->rule.watch) If entry->rule.watch is NULL, audit_compare_rule on 910 is called: audit_compare_rule(&entry->rule, &e->rule)) In audit_compare_rule(), a->watch is used on line 720: if (strcmp(audit_watch_path(a->watch), ...) In this case, a->watch is NULL, and audit_watch_path() will use: watch->path Thus, a possible null-pointer dereference may occur in this case. To fix this possible bug, an if statement is added in audit_compare_rule() to check a->watch before using a->watch. This bug is found by a static analysis tool STCheck written by us. Signed-off-by: Jia-Ju Bai --- kernel/auditfilter.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index b0126e9c0743..b0ad17b14609 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c @@ -717,6 +717,8 @@ static int audit_compare_rule(struct audit_krule *a, struct audit_krule *b) return 1; break; case AUDIT_WATCH: + if (!a->watch) + break; if (strcmp(audit_watch_path(a->watch), audit_watch_path(b->watch))) return 1; -- 2.17.0