Print this page
NEX-13644 File access audit logging
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/c2/audit.c
          +++ new/usr/src/uts/common/c2/audit.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  24   25   */
  25   26  
  26   27  /*
  27   28   * This file contains the audit hook support code for auditing.
  28   29   */
  29   30  
  30   31  #include <sys/types.h>
  31   32  #include <sys/proc.h>
  32   33  #include <sys/vnode.h>
  33   34  #include <sys/vfs.h>
↓ open down ↓ 20 lines elided ↑ open up ↑
  54   55  #include <c2/audit_record.h>
  55   56  #include <sys/strsubr.h>
  56   57  #include <sys/tihdr.h>
  57   58  #include <sys/tiuser.h>
  58   59  #include <sys/timod.h>
  59   60  #include <sys/model.h>          /* for model_t */
  60   61  #include <sys/disp.h>           /* for servicing_interrupt() */
  61   62  #include <sys/devpolicy.h>
  62   63  #include <sys/crypto/ioctladmin.h>
  63   64  #include <sys/cred_impl.h>
       65 +#include <sys/sid.h>
  64   66  #include <inet/kssl/kssl.h>
  65   67  #include <net/pfpolicy.h>
  66   68  
  67   69  static void add_return_token(caddr_t *, unsigned int scid, int err, int rval);
  68   70  
  69   71  static void audit_pathbuild(struct pathname *pnp);
  70   72  
  71   73  
  72   74  /*
  73   75   * ROUTINE:     AUDIT_SAVEPATH
↓ open down ↓ 625 lines elided ↑ open up ↑
 699  701                   */
 700  702                  stp->sd_t_audit_data = NULL;
 701  703                  mutex_exit(&stp->sd_lock);
 702  704                  return;
 703  705          }
 704  706  
 705  707          stp->sd_t_audit_data = (caddr_t)curthread;
 706  708          mutex_exit(&stp->sd_lock);
 707  709  }
 708  710  
      711 +/*
      712 + * ROUTINE:     AUDIT_SACL
      713 + * PURPOSE:     audit ACL-based file accesses
      714 + * CALLBY:      SMB, NFS
      715 + * NOTE:
      716 + *
      717 + * IMPORTANT NOTE: Since we generate an audit record here, we may sleep
      718 + *      on the audit queue if it becomes full.
      719 + * TODO:
      720 + * QUESTION:
      721 + */
      722 +void
      723 +audit_sacl(char *path, cred_t *cr, uint32_t desired, boolean_t success,
      724 +    t_audit_sacl_t *tas)
      725 +{
      726 +        token_t *ad = NULL;
      727 +        au_kcontext_t   *kctx = GET_KCTX_PZ;
      728 +        const auditinfo_addr_t *ainfo;
      729 +        ksid_t *ks;
      730 +
      731 +        /* if auditing not enabled, then don't generate an audit record */
      732 +        if (((kctx->auk_auditstate) &
      733 +            ~(AUC_AUDITING | AUC_INIT_AUDIT | AUC_NOSPACE)) != 0)
      734 +                return;
      735 +
      736 +        if ((success && (tas->tas_smask & desired) == 0) ||
      737 +            (!success && (tas->tas_fmask & desired) == 0))
      738 +                return;
      739 +
      740 +        ainfo = crgetauinfo(cr);
      741 +        if (ainfo == NULL)
      742 +                return;
      743 +
      744 +        au_write((caddr_t *)&(ad), au_to_path_string(path));
      745 +        au_write((caddr_t *)&(ad), au_to_access_mask(desired));
      746 +
      747 +        /* Include the SID if it has one, in case the id is ephemeral */
      748 +        if ((ks = crgetsid(cr, KSID_USER)) != NULL) {
      749 +                au_write((caddr_t *)&(ad), au_to_wsid(ks));
      750 +        }
      751 +        AUDIT_SETSUBJ((caddr_t *)&(ad), cr, ainfo, kctx);
      752 +        au_close(kctx, (caddr_t *)&(ad), AU_OK, AUE_SACL,
      753 +            success ? 0 : PAD_FAILURE, NULL);
      754 +}
      755 +
 709  756  /*
 710  757   * ROUTINE:     AUDIT_CLOSEF
 711  758   * PURPOSE:
 712  759   * CALLBY:      CLOSEF
 713  760   * NOTE:
 714  761   * release per file audit resources when file structure is being released.
 715  762   *
 716  763   * IMPORTANT NOTE: Since we generate an audit record here, we may sleep
 717  764   *      on the audit queue if it becomes full. This means
 718  765   *      audit_closef can not be called when f_count == 0. Since
↓ open down ↓ 1532 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX