summaryrefslogtreecommitdiffstats
path: root/scripts/gdb
AgeCommit message (Expand)Author
2018-01-19scripts/gdb/linux/tasks.py: fix get_thread_infoXi Kangjie
2017-11-02License cleanup: add SPDX GPL-2.0 license identifier to files with no licenseGreg Kroah-Hartman
2017-09-01kbuild: use $(abspath ...) instead of $(shell cd ... && /bin/pwd)Masahiro Yamada
2017-07-12scripts/gdb: lx-dmesg: use explicit encoding=utf8 errors=replaceLeonard Crestez
2017-07-12scripts/gdb: lx-dmesg: cast log_buf to void* for addr fetchLeonard Crestez
2017-07-12scripts/gdb: add lx-fdtdump commandPeter Griffin
2017-06-02scripts/gdb: make lx-dmesg command work (reliably)André Draszik
2016-07-15Revert "scripts/gdb: add a Radix Tree Parser"Kieran Bingham
2016-07-15scripts/gdb: Perform path expansion to lx-symbol's argumentsNikolay Borisov
2016-07-15scripts/gdb: add constants.py to .gitignoreOmar Sandoval
2016-07-15scripts/gdb: rebuild constants.py on dependancy changeKieran Bingham
2016-07-15scripts/gdb: silence 'nothing to do' messageKieran Bingham
2016-05-23scripts/gdb: decode bytestream on dmesg for Python3Kieran Bingham
2016-05-23scripts/gdb: fix issue with dmesg.py and python 3.XDom Cote
2016-05-23scripts/gdb: improve types abstraction for gdb python scriptsDom Cote
2016-05-23scripts/gdb: add lx_thread_info_by_pid helperKieran Bingham
2016-05-23scripts/gdb: add a Radix Tree ParserKieran Bingham
2016-05-23scripts/gdb: cast CPU numbers to integerJan Kiszka
2016-05-23scripts/gdb: add cpu iteratorsKieran Bingham
2016-05-23scripts/gdb: add mount point list commandKieran Bingham
2016-05-23scripts/gdb: add io resource readersKieran Bingham
2016-05-23scripts/gdb: provide a dentry_name VFS path helperKieran Bingham
2016-05-23scripts/gdb: support !CONFIG_MODULES gracefullyKieran Bingham
2016-05-23scripts/gdb: provide exception catching parserKieran Bingham
2016-05-23scripts/gdb: convert modules usage to lists functionsKieran Bingham
2016-05-23scripts/gdb: provide kernel list item generatorsKieran Bingham
2016-05-23scripts/gdb: provide linux constantsKieran Bingham
2016-05-23scripts/gdb: Adjust module reference counter reported by lx-lsmodJan Kiszka
2016-03-22scripts/gdb: account for changes in module data structureJan Kiszka
2016-03-22scripts/gdb: add cmdline reader commandKieran Bingham
2016-03-22scripts/gdb: add version commandKieran Bingham
2015-06-30scripts/gdb: remove useless global instructionThiébaud Weksteen
2015-06-30scripts/gdb: add ps commandThiébaud Weksteen
2015-06-30scripts/gdb: fix PEP8 complianceThiébaud Weksteen
2015-06-30scripts/gdb: fix typo in exception nameThiébaud Weksteen
2015-06-30scripts/gdb: enable completion for lx-list-check parameterJan Kiszka
2015-06-30scripts/gdb: also allow list_head pointer as lx-list-check paramterJan Kiszka
2015-06-30scripts/gdb: add command to check list consistencyThiébaud Weksteen
2015-05-28scripts/gdb: fix lx-lsmod refcntAdrien Schildknecht
2015-02-28scripts/gdb: add empty package initialization scriptJan Kiszka
2015-02-17scripts/gdb: disable pagination while printing from breakpoint handlerJan Kiszka
2015-02-17scripts/gdb: convert CpuList to generator functionJan Kiszka
2015-02-17scripts/gdb: convert ModuleList to generator functionJan Kiszka
2015-02-17scripts/gdb: use a generator instead of iterator for task listDaniel Wagner
2015-02-17scripts/gdb: ignore byte-compiled python filesDaniel Thompson
2015-02-17scripts/gdb: port to python3 / gdb7.7Pantelis Koukousoulas
2015-02-17scripts/gdb: add lx-lsmod commandJan Kiszka
2015-02-17scripts/gdb: add class to iterate over CPU masksJan Kiszka
2015-02-17scripts/gdb: add lx_current convenience functionJan Kiszka
2015-02-17scripts/gdb: add internal helper and convenience function for per-cpu lookupJan Kiszka
372' href='#n372'>372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
// SPDX-License-Identifier: GPL-2.0-or-later
/* audit_watch.c -- watching inodes
 *
 * Copyright 2003-2009 Red Hat, Inc.
 * Copyright 2005 Hewlett-Packard Development Company, L.P.
 * Copyright 2005 IBM Corporation
 */

#include <linux/file.h>
#include <linux/kernel.h>
#include <linux/audit.h>
#include <linux/kthread.h>
#include <linux/mutex.h>
#include <linux/fs.h>
#include <linux/fsnotify_backend.h>
#include <linux/namei.h>
#include <linux/netlink.h>
#include <linux/refcount.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/security.h>
#include "audit.h"

/*
 * Reference counting:
 *
 * audit_parent: lifetime is from audit_init_parent() to receipt of an FS_IGNORED
 * 	event.  Each audit_watch holds a reference to its associated parent.
 *
 * audit_watch: if added to lists, lifetime is from audit_init_watch() to
 * 	audit_remove_watch().  Additionally, an audit_watch may exist
 * 	temporarily to assist in searching existing filter data.  Each
 * 	audit_krule holds a reference to its associated watch.
 */

struct audit_watch {
	refcount_t		count;	/* reference count */
	dev_t			dev;	/* associated superblock device */
	char			*path;	/* insertion path */
	unsigned long		ino;	/* associated inode number */
	struct audit_parent	*parent; /* associated parent */
	struct list_head	wlist;	/* entry in parent->watches list */
	struct list_head	rules;	/* anchor for krule->rlist */
};

struct audit_parent {
	struct list_head	watches; /* anchor for audit_watch->wlist */
	struct fsnotify_mark mark; /* fsnotify mark on the inode */
};

/* fsnotify handle. */
static struct fsnotify_group *audit_watch_group;

/* fsnotify events we care about. */
#define AUDIT_FS_WATCH (FS_MOVE | FS_CREATE | FS_DELETE | FS_DELETE_SELF |\
			FS_MOVE_SELF | FS_EVENT_ON_CHILD | FS_UNMOUNT)

static void audit_free_parent(struct audit_parent *parent)
{
	WARN_ON(!list_empty(&parent->watches));
	kfree(parent);
}

static void audit_watch_free_mark(struct fsnotify_mark *entry)
{
	struct audit_parent *parent;

	parent = container_of(entry, struct audit_parent, mark);
	audit_free_parent(parent);
}

static void audit_get_parent(struct audit_parent *parent)
{
	if (likely(parent))
		fsnotify_get_mark(&parent->mark);
}

static void audit_put_parent(struct audit_parent *parent)
{
	if (likely(parent))
		fsnotify_put_mark(&parent->mark);
}

/*
 * Find and return the audit_parent on the given inode.  If found a reference
 * is taken on this parent.
 */
static inline struct audit_parent *audit_find_parent(struct inode *inode)
{
	struct audit_parent *parent = NULL;
	struct fsnotify_mark *entry;

	entry = fsnotify_find_mark(&inode->i_fsnotify_marks, audit_watch_group);
	if (entry)
		parent = container_of(entry, struct audit_parent, mark);

	return parent;
}

void audit_get_watch(struct audit_watch *watch)
{
	refcount_inc(&watch->count);
}

void audit_put_watch(struct audit_watch *watch)
{
	if (refcount_dec_and_test(&watch->count)) {
		WARN_ON(watch->parent);
		WARN_ON(!list_empty(&watch->rules));
		kfree(watch->path);
		kfree(watch);
	}
}

static void audit_remove_watch(struct audit_watch *watch)
{
	list_del(&watch->wlist);
	audit_put_parent(watch->parent);
	watch->parent = NULL;
	audit_put_watch(watch); /* match initial get */
}

char *audit_watch_path(struct audit_watch *watch)
{
	return watch->path;
}

int audit_watch_compare(struct audit_watch *watch, unsigned long ino, dev_t dev)
{
	return (watch->ino != AUDIT_INO_UNSET) &&
		(watch->ino == ino) &&
		(watch->dev == dev);
}

/* Initialize a parent watch entry. */
static struct audit_parent *audit_init_parent(struct path *path)
{
	struct inode *inode = d_backing_inode(path->dentry);
	struct audit_parent *parent;
	int ret;

	parent = kzalloc(sizeof(*parent), GFP_KERNEL);
	if (unlikely(!parent))
		return ERR_PTR(-ENOMEM);

	INIT_LIST_HEAD(&parent->watches);

	fsnotify_init_mark(&parent->mark, audit_watch_group);
	parent->mark.mask = AUDIT_FS_WATCH;
	ret = fsnotify_add_inode_mark(&parent->mark, inode, 0);
	if (ret < 0) {
		audit_free_parent(parent);
		return ERR_PTR(ret);
	}

	return parent;
}

/* Initialize a watch entry. */
static struct audit_watch *audit_init_watch(char *path)
{
	struct audit_watch *watch;

	watch = kzalloc(sizeof(*watch), GFP_KERNEL);
	if (unlikely(!watch))
		return ERR_PTR(-ENOMEM);

	INIT_LIST_HEAD(&watch->rules);
	refcount_set(&watch->count, 1);
	watch->path = path;
	watch->dev = AUDIT_DEV_UNSET;
	watch->ino = AUDIT_INO_UNSET;

	return watch;
}

/* Translate a watch string to kernel representation. */
int audit_to_watch(struct audit_krule *krule, char *path, int len, u32 op)
{
	struct audit_watch *watch;

	if (!audit_watch_group)
		return -EOPNOTSUPP;

	if (path[0] != '/' || path[len-1] == '/' ||
	    krule->listnr != AUDIT_FILTER_EXIT ||
	    op != Audit_equal ||
	    krule->inode_f || krule->watch || krule->tree)
		return -EINVAL;

	watch = audit_init_watch(path);
	if (IS_ERR(watch))
		return PTR_ERR(watch);

	krule->watch = watch;

	return 0;
}

/* Duplicate the given audit watch.  The new watch's rules list is initialized
 * to an empty list and wlist is undefined. */
static struct audit_watch *audit_dupe_watch(struct audit_watch *old)
{
	char *path;
	struct audit_watch *new;

	path = kstrdup(old->path, GFP_KERNEL);
	if (unlikely(!path))
		return ERR_PTR(-ENOMEM);

	new = audit_init_watch(path);
	if (IS_ERR(new)) {
		kfree(path);
		goto out;
	}

	new->dev = old->dev;
	new->ino = old->ino;
	audit_get_parent(old->parent);
	new->parent = old->parent;

out:
	return new;
}

static void audit_watch_log_rule_change(struct audit_krule *r, struct audit_watch *w, char *op)
{
	struct audit_buffer *ab;

	if (!audit_enabled)
		return;
	ab = audit_log_start(audit_context(), GFP_NOFS, AUDIT_CONFIG_CHANGE);
	if (!ab)
		return;
	audit_log_session_info(ab);
	audit_log_format(ab, "op=%s path=", op);
	audit_log_untrustedstring(ab, w->path);
	audit_log_key(ab, r->filterkey);
	audit_log_format(ab, " list=%d res=1", r->listnr);
	audit_log_end(ab);
}

/* Update inode info in audit rules based on filesystem event. */
static void audit_update_watch(struct audit_parent *parent,
			       const struct qstr *dname, dev_t dev,
			       unsigned long ino, unsigned invalidating)
{
	struct audit_watch *owatch, *nwatch, *nextw;
	struct audit_krule *r, *nextr;
	struct audit_entry *oentry, *nentry;

	mutex_lock(&audit_filter_mutex);
	/* Run all of the watches on this parent looking for the one that
	 * matches the given dname */
	list_for_each_entry_safe(owatch, nextw