From owner-svn-src-all@freebsd.org Tue Mar 22 22:41:15 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B6D1DADA5DD; Tue, 22 Mar 2016 22:41:15 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 75232EB8; Tue, 22 Mar 2016 22:41:15 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u2MMfEWW090166; Tue, 22 Mar 2016 22:41:14 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u2MMfEGF090164; Tue, 22 Mar 2016 22:41:14 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201603222241.u2MMfEGF090164@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Tue, 22 Mar 2016 22:41:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297203 - in head: share/man/man4 sys/dev/filemon X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Mar 2016 22:41:15 -0000 Author: bdrewery Date: Tue Mar 22 22:41:14 2016 New Revision: 297203 URL: https://svnweb.freebsd.org/changeset/base/297203 Log: Handle copyin failures. Skip the log entry as there is nothing good to write out. Don't fail the syscall though since it already succeeded. There's no reason filemon's tracing failure should fail the already-succeeded syscall. Record the error for later to return from close(2) on the filemon devfs file descriptor. Discussed with: markj, sjg, kib (briefly with kib) Reported by: mjg MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Modified: head/share/man/man4/filemon.4 head/sys/dev/filemon/filemon_wrapper.c Modified: head/share/man/man4/filemon.4 ============================================================================== --- head/share/man/man4/filemon.4 Tue Mar 22 22:41:10 2016 (r297202) +++ head/share/man/man4/filemon.4 Tue Mar 22 22:41:14 2016 (r297203) @@ -167,6 +167,15 @@ The system call on the filemon file descriptor may fail with the errors from .Xr write 2 if any error is encountered while writing the log. +It may also fail if: +.Bl -tag -width Er +.It Bq Er EFAULT +An invalid address was used for a traced system call argument, resulting in +no log entry for the system call. +.It Bq Er ENAMETOOLONG +An argument for a traced system call was too long, resulting in +no log entry for the system call. +.El .Sh FILES .Bl -tag -width ".Pa /dev/filemon" .It Pa /dev/filemon Modified: head/sys/dev/filemon/filemon_wrapper.c ============================================================================== --- head/sys/dev/filemon/filemon_wrapper.c Tue Mar 22 22:41:10 2016 (r297202) +++ head/sys/dev/filemon/filemon_wrapper.c Tue Mar 22 22:41:14 2016 (r297203) @@ -72,21 +72,24 @@ filemon_output(struct filemon *filemon, static int filemon_wrapper_chdir(struct thread *td, struct chdir_args *uap) { - int ret; + int error, ret; size_t len; struct filemon *filemon; if ((ret = sys_chdir(td, uap)) == 0) { if ((filemon = filemon_proc_get(curproc)) != NULL) { - copyinstr(uap->path, filemon->fname1, - sizeof(filemon->fname1), NULL); + if ((error = copyinstr(uap->path, filemon->fname1, + sizeof(filemon->fname1), NULL)) != 0) { + filemon->error = error; + goto copyfail; + } len = snprintf(filemon->msgbufr, sizeof(filemon->msgbufr), "C %d %s\n", curproc->p_pid, filemon->fname1); filemon_output(filemon, filemon->msgbufr, len); - +copyfail: filemon_drop(filemon); } } @@ -123,6 +126,7 @@ filemon_event_process_exec(void *arg __u static void _filemon_wrapper_openat(struct thread *td, char *upath, int flags, int fd) { + int error; size_t len; struct file *fp; struct filemon *filemon; @@ -134,8 +138,11 @@ _filemon_wrapper_openat(struct thread *t freepath = NULL; fp = NULL; - copyinstr(upath, filemon->fname1, - sizeof(filemon->fname1), NULL); + if ((error = copyinstr(upath, filemon->fname1, + sizeof(filemon->fname1), NULL)) != 0) { + filemon->error = error; + goto copyfail; + } if (filemon->fname1[0] != '/' && fd != AT_FDCWD) { /* @@ -180,7 +187,7 @@ _filemon_wrapper_openat(struct thread *t curproc->p_pid, atpath, atpath[0] != '\0' ? "/" : "", filemon->fname1); filemon_output(filemon, filemon->msgbufr, len); - +copyfail: filemon_drop(filemon); if (fp != NULL) fdrop(fp, td); @@ -213,23 +220,26 @@ filemon_wrapper_openat(struct thread *td static int filemon_wrapper_rename(struct thread *td, struct rename_args *uap) { - int ret; + int error, ret; size_t len; struct filemon *filemon; if ((ret = sys_rename(td, uap)) == 0) { if ((filemon = filemon_proc_get(curproc)) != NULL) { - copyinstr(uap->from, filemon->fname1, - sizeof(filemon->fname1), NULL); - copyinstr(uap->to, filemon->fname2, - sizeof(filemon->fname2), NULL); + if (((error = copyinstr(uap->from, filemon->fname1, + sizeof(filemon->fname1), NULL)) != 0) || + ((error = copyinstr(uap->to, filemon->fname2, + sizeof(filemon->fname2), NULL)) != 0)) { + filemon->error = error; + goto copyfail; + } len = snprintf(filemon->msgbufr, sizeof(filemon->msgbufr), "M %d '%s' '%s'\n", curproc->p_pid, filemon->fname1, filemon->fname2); filemon_output(filemon, filemon->msgbufr, len); - +copyfail: filemon_drop(filemon); } } @@ -242,19 +252,23 @@ _filemon_wrapper_link(struct thread *td, { struct filemon *filemon; size_t len; + int error; if ((filemon = filemon_proc_get(curproc)) != NULL) { - copyinstr(upath1, filemon->fname1, - sizeof(filemon->fname1), NULL); - copyinstr(upath2, filemon->fname2, - sizeof(filemon->fname2), NULL); + if (((error = copyinstr(upath1, filemon->fname1, + sizeof(filemon->fname1), NULL)) != 0) || + ((error = copyinstr(upath2, filemon->fname2, + sizeof(filemon->fname2), NULL)) != 0)) { + filemon->error = error; + goto copyfail; + } len = snprintf(filemon->msgbufr, sizeof(filemon->msgbufr), "L %d '%s' '%s'\n", curproc->p_pid, filemon->fname1, filemon->fname2); filemon_output(filemon, filemon->msgbufr, len); - +copyfail: filemon_drop(filemon); } } @@ -322,21 +336,24 @@ filemon_event_process_exit(void *arg __u static int filemon_wrapper_unlink(struct thread *td, struct unlink_args *uap) { - int ret; + int error, ret; size_t len; struct filemon *filemon; if ((ret = sys_unlink(td, uap)) == 0) { if ((filemon = filemon_proc_get(curproc)) != NULL) { - copyinstr(uap->path, filemon->fname1, - sizeof(filemon->fname1), NULL); + if ((error = copyinstr(uap->path, filemon->fname1, + sizeof(filemon->fname1), NULL)) != 0) { + filemon->error = error; + goto copyfail; + } len = snprintf(filemon->msgbufr, sizeof(filemon->msgbufr), "D %d %s\n", curproc->p_pid, filemon->fname1); filemon_output(filemon, filemon->msgbufr, len); - +copyfail: filemon_drop(filemon); } }