Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2022-02-03 Thread Casey Schaufler

On 2/3/2022 5:16 AM, Vishal Goel wrote:

   Currently tracer process info is printed in object field in

smack error log for ptrace check which is wrong.
Object process should print the tracee process info.
Tracee info is not printed in the smack error logs.
So it is not possible to debug the ptrace smack issues.

Now changes has been done to print both tracer and tracee
process info in smack error logs for ptrace scenarios

Old logs:-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK fn=smack_ptrace_access_check action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
ocomm="tst_pt"
[  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK fn=smack_ptrace_traceme action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=12685 comm="tst_pt_me" opid=12563 
ocomm="bash"
[ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK fn=smack_bprm_set_creds action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=1778 comm="tst_bprm" opid=1776 
ocomm="tst_bprm"

New logs:-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK fn=smack_ptrace_access_check action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=5189 tracer-comm="tst_pt" pid=5189 
comm="tst_pt" tracee-pid=962 tracee-comm="test_tracee"
[  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK fn=smack_ptrace_traceme action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=6161 tracer-comm="bash" pid=6310 
comm="tst_pt_me" tracee-pid=6310 tracee-comm="tst_pt_me"
[ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK fn=smack_bprm_set_creds action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=6435 tracer-comm="tst_bprm" pid=6436 
comm="tst_bprm" tracee-pid=6436 tracee-comm="tst_bprm"

Signed-off-by: Vishal Goel 

Does anyone from the audit side object to my taking this
in the Smack tree?

The audit subsystem already has the "opid" and "ocomm" fields for
reporting on the object task info and this is even available in
dump_common_audit_data() via LSM_AUDIT_DATA_TASK; is there a reason
that can't be used instead?

That info is not sufficient for debugging smack issues in ptrace calls.
Tracee information is not printed in the logs. For eg. in below log-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK fn=smack_ptrace_access_check action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
ocomm="tst_pt"

There is no information of the tracee process.
So to debug such ptrace issues, both tracer and tracee information is needed.
That's why added new type to print both info specifically for ptrace scenarios.

  From what I saw you are trying to record information about the tracer
and the tracee, yes?  The "pid", "comm", "opid", and "ocomm" fields
should be used instead of adding new fields.

Actually in smack_ptrace_access_check() function, tracer process is current 
process.
While some other process is object process(tracee).
But in case of smack_ptrace_traceme() function, tracer process is parent 
process.
While current process is object process(tracee). So in this case, both pid/comm
and opid/ocomm will print current process info only i.e tracess process.
So tracer process info is not getting printed.
Similarly for smack_bprm_creds_for_exec(), tracer process is parent process.
And current process is tracee process.
So that's why we need to print separately tracer and tracee process info
without any confusion.

The last time I checked, Smack's access controls operated as
subject-verb-object triple, which should map nicely to the
"pid"/"comm" and "opid"/"ocomm" fields; the former pair associated
with the subject, the latter pair associated with the object.  That
combined with the "fn" field should give you all of the information
relevant to the access control decision.  If you feel that is not the
case, perhaps that is an indicator that the information used in the
access control decision is wrong, or there is a problem with the
implementation.
  

Sorry that I've been absent from this discussion. Paul's right.
There's a whole lot of unnecessary complexity in this patch.
If you change the 2nd parameter of smk_ptrace_rule_check() to
be the task_struct of the tracee you should be able to do
exactly as Paul suggests.

Yes,right. We can map the "opid/ocomm" pair to object/tracee process.
But issue is to print subject info. In smack, subject can be current process
or it can be parent of current process in some api.
For eg. in smack_ptrace_access_check() function, subject/tracer process is 
current process.
While in case of smack_ptrace_traceme() function, subject/tracer process is 
parent process.
But as you know, that "pid/comm" pair always maps to current process according 
to below code:-

static void dump_common_audit_data(struct audit_buffer *ab,
struct 

RE: Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2022-02-03 Thread Vishal Goel
  Currently tracer process info is printed in object field in
 smack error log for ptrace check which is wrong.
 Object process should print the tracee process info.
 Tracee info is not printed in the smack error logs.
 So it is not possible to debug the ptrace smack issues.

 Now changes has been done to print both tracer and tracee
 process info in smack error logs for ptrace scenarios

 Old logs:-
 [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
 fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
 object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
 ocomm="tst_pt"
 [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
 fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" 
 object="Tracee_lbl" requested= pid=12685 comm="tst_pt_me" opid=12563 
 ocomm="bash"
 [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
 fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 
 object="Tracee_lbl" requested= pid=1778 comm="tst_bprm" opid=1776 
 ocomm="tst_bprm"

 New logs:-
 [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
 fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
 object="Tracee_lbl" requested= tracer-pid=5189 tracer-comm="tst_pt" 
 pid=5189 comm="tst_pt" tracee-pid=962 tracee-comm="test_tracee"
 [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
 fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" 
 object="Tracee_lbl" requested= tracer-pid=6161 tracer-comm="bash" 
 pid=6310 comm="tst_pt_me" tracee-pid=6310 tracee-comm="tst_pt_me"
 [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
 fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 
 object="Tracee_lbl" requested= tracer-pid=6435 tracer-comm="tst_bprm" 
 pid=6436 comm="tst_bprm" tracee-pid=6436 tracee-comm="tst_bprm"

 Signed-off-by: Vishal Goel 
>>> Does anyone from the audit side object to my taking this
>>> in the Smack tree?
>> The audit subsystem already has the "opid" and "ocomm" fields for
>> reporting on the object task info and this is even available in
>> dump_common_audit_data() via LSM_AUDIT_DATA_TASK; is there a reason
>> that can't be used instead?
> That info is not sufficient for debugging smack issues in ptrace calls.
> Tracee information is not printed in the logs. For eg. in below log-
> [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
> fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
> object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
> ocomm="tst_pt"
>
> There is no information of the tracee process.
> So to debug such ptrace issues, both tracer and tracee information is 
> needed.
> That's why added new type to print both info specifically for ptrace 
> scenarios.
>>>
  From what I saw you are trying to record information about the tracer
 and the tracee, yes?  The "pid", "comm", "opid", and "ocomm" fields
 should be used instead of adding new fields.
>>> Actually in smack_ptrace_access_check() function, tracer process is current 
>>> process.
>>> While some other process is object process(tracee).
>>> But in case of smack_ptrace_traceme() function, tracer process is parent 
>>> process.
>>> While current process is object process(tracee). So in this case, both 
>>> pid/comm
>>> and opid/ocomm will print current process info only i.e tracess process.
>>> So tracer process info is not getting printed.
>>> Similarly for smack_bprm_creds_for_exec(), tracer process is parent process.
>>> And current process is tracee process.
>>> So that's why we need to print separately tracer and tracee process info
>>> without any confusion.
>> The last time I checked, Smack's access controls operated as
>> subject-verb-object triple, which should map nicely to the
>> "pid"/"comm" and "opid"/"ocomm" fields; the former pair associated
>> with the subject, the latter pair associated with the object.  That
>> combined with the "fn" field should give you all of the information
>> relevant to the access control decision.  If you feel that is not the
>> case, perhaps that is an indicator that the information used in the
>> access control decision is wrong, or there is a problem with the
>> implementation.
 
> Sorry that I've been absent from this discussion. Paul's right.
> There's a whole lot of unnecessary complexity in this patch.
> If you change the 2nd parameter of smk_ptrace_rule_check() to
> be the task_struct of the tracee you should be able to do
> exactly as Paul suggests.

Yes,right. We can map the "opid/ocomm" pair to object/tracee process. 
But 

RE: Re: Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2022-02-03 Thread Vishal Goel
> Currently tracer process info is printed in object field in
> smack error log for ptrace check which is wrong.
> Object process should print the tracee process info.
> Tracee info is not printed in the smack error logs.
> So it is not possible to debug the ptrace smack issues.
>
> Now changes has been done to print both tracer and tracee
> process info in smack error logs for ptrace scenarios
>
> Old logs:-
> [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
> fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
> object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
> ocomm="tst_pt"
> [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
> fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" 
> object="Tracee_lbl" requested= pid=12685 comm="tst_pt_me" opid=12563 
> ocomm="bash"
> [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
> fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 
> object="Tracee_lbl" requested= pid=1778 comm="tst_bprm" opid=1776 
> ocomm="tst_bprm"
>
> New logs:-
> [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
> fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
> object="Tracee_lbl" requested= tracer-pid=5189 tracer-comm="tst_pt" 
> pid=5189 comm="tst_pt" tracee-pid=962 tracee-comm="test_tracee"
> [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
> fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" 
> object="Tracee_lbl" requested= tracer-pid=6161 tracer-comm="bash" 
> pid=6310 comm="tst_pt_me" tracee-pid=6310 tracee-comm="tst_pt_me"
> [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
> fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 
> object="Tracee_lbl" requested= tracer-pid=6435 tracer-comm="tst_bprm" 
> pid=6436 comm="tst_bprm" tracee-pid=6436 tracee-comm="tst_bprm"
>
> Signed-off-by: Vishal Goel 

 Does anyone from the audit side object to my taking this
 in the Smack tree?
>>
>>> The audit subsystem already has the "opid" and "ocomm" fields for
>>> reporting on the object task info and this is even available in
>>> dump_common_audit_data() via LSM_AUDIT_DATA_TASK; is there a reason
>>> that can't be used instead?
>>
>> That info is not sufficient for debugging smack issues in ptrace calls.
>> Tracee information is not printed in the logs. For eg. in below log-
>> [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
>> fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
>> object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
>> ocomm="tst_pt"
>>
>> There is no information of the tracee process.
>> So to debug such ptrace issues, both tracer and tracee information is needed.
>> That's why added new type to print both info specifically for ptrace 
>> scenarios.
 

> From what I saw you are trying to record information about the tracer
> and the tracee, yes?  The "pid", "comm", "opid", and "ocomm" fields
> should be used instead of adding new fields.

Actually in smack_ptrace_access_check() function, tracer process is current 
process.
While some other process is object process(tracee).
But in case of smack_ptrace_traceme() function, tracer process is parent 
process.
While current process is object process(tracee). So in this case, both pid/comm
and opid/ocomm will print current process info only i.e tracess process.
So tracer process info is not getting printed.
Similarly for smack_bprm_creds_for_exec(), tracer process is parent process.
And current process is tracee process.
So that's why we need to print separately tracer and tracee process info
without any confusion.
 
- Original Message -
Sender : Paul Moore 
Date : 2022-02-01 23:05 (GMT+9)
Title : Re: Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in 
ptrace error logs
 
On Tue, Feb 1, 2022 at 2:55 AM Vishal Goel  wrote:
> >>> Currently tracer process info is printed in object field in
> >>> smack error log for ptrace check which is wrong.
> >>> Object process should print the tracee process info.
> >>> Tracee info is not printed in the smack error logs.
> >>> So it is not possible to debug the ptrace smack issues.
> >>>
> >>> Now changes has been done to print both tracer and tracee
> >>> process info in smack error logs for ptrace scenarios
> >>>
> >>> Old logs:-
> >>> [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
>fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
>object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 ocomm="tst_pt"
> >>> [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
>fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" object="Tracee_lbl" 
>requested= pid=12685 comm="tst_pt_me" opid=12563 ocomm="bash"
> >>> [ 1445.259319] 

Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2022-02-02 Thread Casey Schaufler

On 2/2/2022 7:20 AM, Paul Moore wrote:

On Wed, Feb 2, 2022 at 5:38 AM Vishal Goel  wrote:

Currently tracer process info is printed in object field in
smack error log for ptrace check which is wrong.
Object process should print the tracee process info.
Tracee info is not printed in the smack error logs.
So it is not possible to debug the ptrace smack issues.

Now changes has been done to print both tracer and tracee
process info in smack error logs for ptrace scenarios

Old logs:-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK fn=smack_ptrace_access_check action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
ocomm="tst_pt"
[  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK fn=smack_ptrace_traceme action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=12685 comm="tst_pt_me" opid=12563 
ocomm="bash"
[ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK fn=smack_bprm_set_creds action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=1778 comm="tst_bprm" opid=1776 
ocomm="tst_bprm"

New logs:-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK fn=smack_ptrace_access_check action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=5189 tracer-comm="tst_pt" pid=5189 
comm="tst_pt" tracee-pid=962 tracee-comm="test_tracee"
[  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK fn=smack_ptrace_traceme action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=6161 tracer-comm="bash" pid=6310 
comm="tst_pt_me" tracee-pid=6310 tracee-comm="tst_pt_me"
[ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK fn=smack_bprm_set_creds action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=6435 tracer-comm="tst_bprm" pid=6436 
comm="tst_bprm" tracee-pid=6436 tracee-comm="tst_bprm"

Signed-off-by: Vishal Goel 

Does anyone from the audit side object to my taking this
in the Smack tree?

The audit subsystem already has the "opid" and "ocomm" fields for
reporting on the object task info and this is even available in
dump_common_audit_data() via LSM_AUDIT_DATA_TASK; is there a reason
that can't be used instead?

That info is not sufficient for debugging smack issues in ptrace calls.
Tracee information is not printed in the logs. For eg. in below log-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK fn=smack_ptrace_access_check action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
ocomm="tst_pt"

There is no information of the tracee process.
So to debug such ptrace issues, both tracer and tracee information is needed.
That's why added new type to print both info specifically for ptrace scenarios.



 From what I saw you are trying to record information about the tracer
and the tracee, yes?  The "pid", "comm", "opid", and "ocomm" fields
should be used instead of adding new fields.

Actually in smack_ptrace_access_check() function, tracer process is current 
process.
While some other process is object process(tracee).
But in case of smack_ptrace_traceme() function, tracer process is parent 
process.
While current process is object process(tracee). So in this case, both pid/comm
and opid/ocomm will print current process info only i.e tracess process.
So tracer process info is not getting printed.
Similarly for smack_bprm_creds_for_exec(), tracer process is parent process.
And current process is tracee process.
So that's why we need to print separately tracer and tracee process info
without any confusion.

The last time I checked, Smack's access controls operated as
subject-verb-object triple, which should map nicely to the
"pid"/"comm" and "opid"/"ocomm" fields; the former pair associated
with the subject, the latter pair associated with the object.  That
combined with the "fn" field should give you all of the information
relevant to the access control decision.  If you feel that is not the
case, perhaps that is an indicator that the information used in the
access control decision is wrong, or there is a problem with the
implementation.


Sorry that I've been absent from this discussion. Paul's right.
There's a whole lot of unnecessary complexity in this patch.
If you change the 2nd parameter of smk_ptrace_rule_check() to
be the task_struct of the tracee you should be able to do
exactly as Paul suggests.



--
paul-moore.com


--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



Re: Re: Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2022-02-02 Thread Paul Moore
On Wed, Feb 2, 2022 at 5:38 AM Vishal Goel  wrote:
> > Currently tracer process info is printed in object field in
> > smack error log for ptrace check which is wrong.
> > Object process should print the tracee process info.
> > Tracee info is not printed in the smack error logs.
> > So it is not possible to debug the ptrace smack issues.
> >
> > Now changes has been done to print both tracer and tracee
> > process info in smack error logs for ptrace scenarios
> >
> > Old logs:-
> > [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
> > fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
> > object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
> > ocomm="tst_pt"
> > [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
> > fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" 
> > object="Tracee_lbl" requested= pid=12685 comm="tst_pt_me" opid=12563 
> > ocomm="bash"
> > [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
> > fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 
> > object="Tracee_lbl" requested= pid=1778 comm="tst_bprm" opid=1776 
> > ocomm="tst_bprm"
> >
> > New logs:-
> > [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
> > fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
> > object="Tracee_lbl" requested= tracer-pid=5189 tracer-comm="tst_pt" 
> > pid=5189 comm="tst_pt" tracee-pid=962 tracee-comm="test_tracee"
> > [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
> > fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" 
> > object="Tracee_lbl" requested= tracer-pid=6161 tracer-comm="bash" 
> > pid=6310 comm="tst_pt_me" tracee-pid=6310 tracee-comm="tst_pt_me"
> > [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
> > fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 
> > object="Tracee_lbl" requested= tracer-pid=6435 tracer-comm="tst_bprm" 
> > pid=6436 comm="tst_bprm" tracee-pid=6436 tracee-comm="tst_bprm"
> >
> > Signed-off-by: Vishal Goel 
> 
>  Does anyone from the audit side object to my taking this
>  in the Smack tree?
> >>
> >>> The audit subsystem already has the "opid" and "ocomm" fields for
> >>> reporting on the object task info and this is even available in
> >>> dump_common_audit_data() via LSM_AUDIT_DATA_TASK; is there a reason
> >>> that can't be used instead?
> >>
> >> That info is not sufficient for debugging smack issues in ptrace calls.
> >> Tracee information is not printed in the logs. For eg. in below log-
> >> [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
> >> fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
> >> object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
> >> ocomm="tst_pt"
> >>
> >> There is no information of the tracee process.
> >> So to debug such ptrace issues, both tracer and tracee information is 
> >> needed.
> >> That's why added new type to print both info specifically for ptrace 
> >> scenarios.
>
>
> > From what I saw you are trying to record information about the tracer
> > and the tracee, yes?  The "pid", "comm", "opid", and "ocomm" fields
> > should be used instead of adding new fields.
>
> Actually in smack_ptrace_access_check() function, tracer process is current 
> process.
> While some other process is object process(tracee).
> But in case of smack_ptrace_traceme() function, tracer process is parent 
> process.
> While current process is object process(tracee). So in this case, both 
> pid/comm
> and opid/ocomm will print current process info only i.e tracess process.
> So tracer process info is not getting printed.
> Similarly for smack_bprm_creds_for_exec(), tracer process is parent process.
> And current process is tracee process.
> So that's why we need to print separately tracer and tracee process info
> without any confusion.

The last time I checked, Smack's access controls operated as
subject-verb-object triple, which should map nicely to the
"pid"/"comm" and "opid"/"ocomm" fields; the former pair associated
with the subject, the latter pair associated with the object.  That
combined with the "fn" field should give you all of the information
relevant to the access control decision.  If you feel that is not the
case, perhaps that is an indicator that the information used in the
access control decision is wrong, or there is a problem with the
implementation.

--
paul-moore.com


--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



RE: Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2022-02-01 Thread Vishal Goel
>>> Currently tracer process info is printed in object field in
>>> smack error log for ptrace check which is wrong.
>>> Object process should print the tracee process info.
>>> Tracee info is not printed in the smack error logs.
>>> So it is not possible to debug the ptrace smack issues.
>>>
>>> Now changes has been done to print both tracer and tracee
>>> process info in smack error logs for ptrace scenarios
>>>
>>> Old logs:-
>>> [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
>>> fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
>>> object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
>>> ocomm="tst_pt"
>>> [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
>>> fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" 
>>> object="Tracee_lbl" requested= pid=12685 comm="tst_pt_me" opid=12563 
>>> ocomm="bash"
>>> [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
>>> fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 
>>> object="Tracee_lbl" requested= pid=1778 comm="tst_bprm" opid=1776 
>>> ocomm="tst_bprm"
>>>
>>> New logs:-
>>> [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
>>> fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
>>> object="Tracee_lbl" requested= tracer-pid=5189 tracer-comm="tst_pt" 
>>> pid=5189 comm="tst_pt" tracee-pid=962 tracee-comm="test_tracee"
>>> [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
>>> fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" 
>>> object="Tracee_lbl" requested= tracer-pid=6161 tracer-comm="bash" pid=6310 
>>> comm="tst_pt_me" tracee-pid=6310 tracee-comm="tst_pt_me"
>>> [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
>>> fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 
>>> object="Tracee_lbl" requested= tracer-pid=6435 tracer-comm="tst_bprm" 
>>> pid=6436 comm="tst_bprm" tracee-pid=6436 tracee-comm="tst_bprm"
>>>
>>> Signed-off-by: Vishal Goel 
>>
>> Does anyone from the audit side object to my taking this
>> in the Smack tree?
 
> The audit subsystem already has the "opid" and "ocomm" fields for
> reporting on the object task info and this is even available in
> dump_common_audit_data() via LSM_AUDIT_DATA_TASK; is there a reason
> that can't be used instead?

That info is not sufficient for debugging smack issues in ptrace calls. 
Tracee information is not printed in the logs. For eg. in below log-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 ocomm="tst_pt"

There is no information of the tracee process.
So to debug such ptrace issues, both tracer and tracee information is needed.
That's why added new type to print both info specifically for ptrace scenarios.


Thanks & Regards
Vishal Goel
 
- Original Message -
Sender : Paul Moore 
Date : 2022-01-29 03:00 (GMT+9)
Title : Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace 
error logs
 
On Fri, Jan 28, 2022 at 11:25 AM Casey Schaufler  wrote:
> On 12/20/2021 2:13 AM, Vishal Goel wrote:
> > Currently tracer process info is printed in object field in
> > smack error log for ptrace check which is wrong.
> > Object process should print the tracee process info.
> > Tracee info is not printed in the smack error logs.
> > So it is not possible to debug the ptrace smack issues.
> >
> > Now changes has been done to print both tracer and tracee
> > process info in smack error logs for ptrace scenarios
> >
> > Old logs:-
> > [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
>fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
>object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 ocomm="tst_pt"
> > [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
>fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" object="Tracee_lbl" 
>requested= pid=12685 comm="tst_pt_me" opid=12563 ocomm="bash"
> > [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
>fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" object="Tracee_lbl" 
>requested= pid=1778 comm="tst_bprm" opid=1776 ocomm="tst_bprm"
> >
> > New logs:-
> > [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
>fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
>object="Tracee_lbl" requested= tracer-pid=5189 tracer-comm="tst_pt" pid=5189 
>comm="tst_pt" tracee-pid=962 tracee-comm="test_tracee"
> > [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
>fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" object="Tracee_lbl" 
>requested= tracer-pid=6161 tracer-comm="bash" pid=6310 comm="tst_pt_me" 
>tracee-pid=6310 tracee-comm="tst_pt_me"
> > [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
>fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 

Re: Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2022-02-01 Thread Paul Moore
On Tue, Feb 1, 2022 at 2:55 AM Vishal Goel  wrote:
> >>> Currently tracer process info is printed in object field in
> >>> smack error log for ptrace check which is wrong.
> >>> Object process should print the tracee process info.
> >>> Tracee info is not printed in the smack error logs.
> >>> So it is not possible to debug the ptrace smack issues.
> >>>
> >>> Now changes has been done to print both tracer and tracee
> >>> process info in smack error logs for ptrace scenarios
> >>>
> >>> Old logs:-
> >>> [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
> >>> fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
> >>> object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
> >>> ocomm="tst_pt"
> >>> [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
> >>> fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" 
> >>> object="Tracee_lbl" requested= pid=12685 comm="tst_pt_me" opid=12563 
> >>> ocomm="bash"
> >>> [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
> >>> fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 
> >>> object="Tracee_lbl" requested= pid=1778 comm="tst_bprm" opid=1776 
> >>> ocomm="tst_bprm"
> >>>
> >>> New logs:-
> >>> [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
> >>> fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
> >>> object="Tracee_lbl" requested= tracer-pid=5189 tracer-comm="tst_pt" 
> >>> pid=5189 comm="tst_pt" tracee-pid=962 tracee-comm="test_tracee"
> >>> [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
> >>> fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" 
> >>> object="Tracee_lbl" requested= tracer-pid=6161 tracer-comm="bash" 
> >>> pid=6310 comm="tst_pt_me" tracee-pid=6310 tracee-comm="tst_pt_me"
> >>> [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
> >>> fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 
> >>> object="Tracee_lbl" requested= tracer-pid=6435 tracer-comm="tst_bprm" 
> >>> pid=6436 comm="tst_bprm" tracee-pid=6436 tracee-comm="tst_bprm"
> >>>
> >>> Signed-off-by: Vishal Goel 
> >>
> >> Does anyone from the audit side object to my taking this
> >> in the Smack tree?
>
> > The audit subsystem already has the "opid" and "ocomm" fields for
> > reporting on the object task info and this is even available in
> > dump_common_audit_data() via LSM_AUDIT_DATA_TASK; is there a reason
> > that can't be used instead?
>
> That info is not sufficient for debugging smack issues in ptrace calls.
> Tracee information is not printed in the logs. For eg. in below log-
> [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
> fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
> object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 ocomm="tst_pt"
>
> There is no information of the tracee process.
> So to debug such ptrace issues, both tracer and tracee information is needed.
> That's why added new type to print both info specifically for ptrace 
> scenarios.

[NOTE: please only send plaintext email to the lists]

>From what I saw you are trying to record information about the tracer
and the tracee, yes?  The "pid", "comm", "opid", and "ocomm" fields
should be used instead of adding new fields.

-- 
paul-moore.com


--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2022-01-28 Thread Paul Moore
On Fri, Jan 28, 2022 at 11:25 AM Casey Schaufler  wrote:
> On 12/20/2021 2:13 AM, Vishal Goel wrote:
> > Currently tracer process info is printed in object field in
> > smack error log for ptrace check which is wrong.
> > Object process should print the tracee process info.
> > Tracee info is not printed in the smack error logs.
> > So it is not possible to debug the ptrace smack issues.
> >
> > Now changes has been done to print both tracer and tracee
> > process info in smack error logs for ptrace scenarios
> >
> > Old logs:-
> > [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
> > fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
> > object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
> > ocomm="tst_pt"
> > [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
> > fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" 
> > object="Tracee_lbl" requested= pid=12685 comm="tst_pt_me" opid=12563 
> > ocomm="bash"
> > [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
> > fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 
> > object="Tracee_lbl" requested= pid=1778 comm="tst_bprm" opid=1776 
> > ocomm="tst_bprm"
> >
> > New logs:-
> > [  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK 
> > fn=smack_ptrace_access_check action=denied subject="Tracer_lbl" 
> > object="Tracee_lbl" requested= tracer-pid=5189 tracer-comm="tst_pt" 
> > pid=5189 comm="tst_pt" tracee-pid=962 tracee-comm="test_tracee"
> > [  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK 
> > fn=smack_ptrace_traceme action=denied subject="Tracer_lbl" 
> > object="Tracee_lbl" requested= tracer-pid=6161 tracer-comm="bash" pid=6310 
> > comm="tst_pt_me" tracee-pid=6310 tracee-comm="tst_pt_me"
> > [ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK 
> > fn=smack_bprm_set_creds action=denied subject="Tracer_lbl" 
> > object="Tracee_lbl" requested= tracer-pid=6435 tracer-comm="tst_bprm" 
> > pid=6436 comm="tst_bprm" tracee-pid=6436 tracee-comm="tst_bprm"
> >
> > Signed-off-by: Vishal Goel 
>
> Does anyone from the audit side object to my taking this
> in the Smack tree?

The audit subsystem already has the "opid" and "ocomm" fields for
reporting on the object task info and this is even available in
dump_common_audit_data() via LSM_AUDIT_DATA_TASK; is there a reason
that can't be used instead?

-- 
paul-moore.com


--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2022-01-28 Thread Casey Schaufler

On 12/20/2021 2:13 AM, Vishal Goel wrote:

Currently tracer process info is printed in object field in
smack error log for ptrace check which is wrong.
Object process should print the tracee process info.
Tracee info is not printed in the smack error logs.
So it is not possible to debug the ptrace smack issues.

Now changes has been done to print both tracer and tracee
process info in smack error logs for ptrace scenarios

Old logs:-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK fn=smack_ptrace_access_check action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
ocomm="tst_pt"
[  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK fn=smack_ptrace_traceme action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=12685 comm="tst_pt_me" opid=12563 
ocomm="bash"
[ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK fn=smack_bprm_set_creds action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=1778 comm="tst_bprm" opid=1776 
ocomm="tst_bprm"

New logs:-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK fn=smack_ptrace_access_check action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=5189 tracer-comm="tst_pt" pid=5189 
comm="tst_pt" tracee-pid=962 tracee-comm="test_tracee"
[  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK fn=smack_ptrace_traceme action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=6161 tracer-comm="bash" pid=6310 
comm="tst_pt_me" tracee-pid=6310 tracee-comm="tst_pt_me"
[ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK fn=smack_bprm_set_creds action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=6435 tracer-comm="tst_bprm" pid=6436 
comm="tst_bprm" tracee-pid=6436 tracee-comm="tst_bprm"

Signed-off-by: Vishal Goel 


Does anyone from the audit side object to my taking this
in the Smack tree?


---
  include/linux/lsm_audit.h |  1 +
  security/lsm_audit.c  | 15 +++
  security/smack/smack.h| 19 +++
  security/smack/smack_access.c | 16 
  security/smack/smack_lsm.c| 33 ++---
  5 files changed, 73 insertions(+), 11 deletions(-)

diff --git a/include/linux/lsm_audit.h b/include/linux/lsm_audit.h
index 17d02eda9..6d752ea16 100644
--- a/include/linux/lsm_audit.h
+++ b/include/linux/lsm_audit.h
@@ -76,6 +76,7 @@ struct common_audit_data {
  #define LSM_AUDIT_DATA_IBENDPORT 14
  #define LSM_AUDIT_DATA_LOCKDOWN 15
  #define LSM_AUDIT_DATA_NOTIFICATION 16
+#define LSM_AUDIT_DATA_PTRACE   17
union   {
struct path path;
struct dentry *dentry;
diff --git a/security/lsm_audit.c b/security/lsm_audit.c
index 1897cbf6f..069e0282c 100644
--- a/security/lsm_audit.c
+++ b/security/lsm_audit.c
@@ -318,6 +318,21 @@ static void dump_common_audit_data(struct audit_buffer *ab,
}
break;
}
+   case LSM_AUDIT_DATA_PTRACE: {
+   struct task_struct *tsk = a->u.tsk;
+   if (tsk) {
+   pid_t pid = task_tgid_nr(tsk);
+
+   if (pid) {
+   char comm[sizeof(tsk->comm)];
+
+   audit_log_format(ab, " tracee-pid=%d 
tracee-comm=", pid);
+   audit_log_untrustedstring(ab,
+   memcpy(comm, tsk->comm, sizeof(comm)));
+   }
+   }
+   break;
+   }
case LSM_AUDIT_DATA_NET:
if (a->u.net->sk) {
const struct sock *sk = a->u.net->sk;
diff --git a/security/smack/smack.h b/security/smack/smack.h
index 99c342259..901228205 100644
--- a/security/smack/smack.h
+++ b/security/smack/smack.h
@@ -266,6 +266,7 @@ struct smack_audit_data {
char *object;
char *request;
int result;
+   struct task_struct *tracer_tsk;
  };
  
  /*

@@ -497,6 +498,16 @@ static inline void smk_ad_setfield_u_net_sk(struct 
smk_audit_info *a,
  {
a->a.u.net->sk = sk;
  }
+static inline void smk_ad_setfield_u_tracer(struct smk_audit_info *a,
+struct task_struct *t)
+{
+   a->a.smack_audit_data->tracer_tsk = t;
+}
+static inline void smk_ad_setfield_u_tracee(struct smk_audit_info *a,
+struct task_struct *t)
+{
+   a->a.u.tsk = t;
+}
  
  #else /* no AUDIT */
  
@@ -524,6 +535,14 @@ static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,

struct sock *sk)
  {
  }
+static inline void smk_ad_setfield_u_tracer(struct smk_audit_info *a,
+   struct task_struct *t)
+{
+}
+static inline void smk_ad_setfield_u_tracee(struct smk_audit_info *a,
+ 

RE: Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2021-12-30 Thread Vishal Goel


Hi,
 
> Signed-off-by: Vishal Goel Could you include a permissive license with this code?>I'd like to add it or a derivative of it to the Smack test suite.
 
You can use below license:-
# SPDX-License-Identifier: GPL-2.0-or-later# Smack Ptrace test cases for smack testsuite infrastructure.# Copyright (C) Vishal Goel  2021
>> Test case for 1st log:->> void main(int argc,char *argv[])>> {>>  int pid;  if (argc < 2) {>>  printf("enter pid of the tracee process\n");>>  exit(0);>>  }  pid = atoi(argv[1]);>>  fprintf(stderr,"Inside\n");>>  ptrace(PTRACE_ATTACH, pid,NULL,NULL);>>  while(1)>>  {>>  sleep(10);>>  }>> } Test case for 2nd log:->> void main(int argc,char *argv[])>> {>>  int pid;  pid = getpid();>>  fprintf(stderr,"Inside\n");>>  ptrace(PTRACE_TRACEME, pid,NULL,NULL);>>  while(1)>>  {>> sleep(10);>>  }>> } Test case for 3rd log:->> void main()>> {>>  int pid;>>  char *argv[2];  fprintf(stderr,"Inside\n");>>  pid = fork();>>  if(pid == 0) {>>  argv[0] = "/tst_pt";>>  argv[1] = NULL;  if(ptrace(PTRACE_TRACEME, pid,NULL,NULL))>>  printf("attached child\n");  printf("going for exec\n");>>  execv("/tst_pt",argv);>>  }>>  else>>  {>>  while(1)>>  {>>  sleep(10);>>  }>>  }>> }>> Added linux-audit to the CC list.
ThanksVishal Goel --
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit

Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2021-12-21 Thread Casey Schaufler

On 12/21/2021 5:12 AM, Vishal Goel wrote:

Hi,


Signed-off-by: Vishal Goel 

What test case do you have that generates these records?


Could you include a permissive license with this code?
I'd like to add it or a derivative of it to the Smack test suite.


Test case for 1st log:-
void main(int argc,char *argv[])
{
 int pid;

 if (argc < 2) {
 printf("enter pid of the tracee process\n");
 exit(0);
 }

 pid = atoi(argv[1]);
 fprintf(stderr,"Inside\n");
 ptrace(PTRACE_ATTACH, pid,NULL,NULL);
 while(1)
 {
 sleep(10);
 }
}

Test case for 2nd log:-
void main(int argc,char *argv[])
{
 int pid;

 pid = getpid();
 fprintf(stderr,"Inside\n");
 ptrace(PTRACE_TRACEME, pid,NULL,NULL);
 while(1)
 {
sleep(10);
 }
}

Test case for 3rd log:-
void main()
{
 int pid;
 char *argv[2];

 fprintf(stderr,"Inside\n");
 pid = fork();
 if(pid == 0) {
 argv[0] = "/tst_pt";
 argv[1] = NULL;

 if(ptrace(PTRACE_TRACEME, pid,NULL,NULL))
 printf("attached child\n");

 printf("going for exec\n");
 execv("/tst_pt",argv);
 }
 else
 {
 while(1)
 {
 sleep(10);
 }
 }
}


Added linux-audit to the CC list.


Thanks
Vishal Goel


--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



RE: Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2021-12-21 Thread Vishal Goel
Hi,

>>> Signed-off-by: Vishal Goel 
> 
> What test case do you have that generates these records?

Test case for 1st log:-
void main(int argc,char *argv[])
{
int pid;

if (argc < 2) {
printf("enter pid of the tracee process\n");
exit(0);
}

pid = atoi(argv[1]);
fprintf(stderr,"Inside\n");
ptrace(PTRACE_ATTACH, pid,NULL,NULL);
while(1)
{
sleep(10);
}
}

Test case for 2nd log:-
void main(int argc,char *argv[])
{
int pid;

pid = getpid();
fprintf(stderr,"Inside\n");
ptrace(PTRACE_TRACEME, pid,NULL,NULL);
while(1)
{
   sleep(10);
}
}

Test case for 3rd log:-
void main()
{
int pid;
char *argv[2];

fprintf(stderr,"Inside\n");
pid = fork();
if(pid == 0) {
argv[0] = "/tst_pt";
argv[1] = NULL;

if(ptrace(PTRACE_TRACEME, pid,NULL,NULL))
printf("attached child\n");

printf("going for exec\n");
execv("/tst_pt",argv);
}
else
{
while(1)
{
sleep(10);
}
}
}

>>
>> Added linux-audit to the CC list.
>>

Thanks
Vishal Goel

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2021-12-20 Thread Casey Schaufler

On 12/20/2021 8:41 AM, Casey Schaufler wrote:

On 12/20/2021 2:13 AM, Vishal Goel wrote:

Currently tracer process info is printed in object field in
smack error log for ptrace check which is wrong.
Object process should print the tracee process info.
Tracee info is not printed in the smack error logs.
So it is not possible to debug the ptrace smack issues.

Now changes has been done to print both tracer and tracee
process info in smack error logs for ptrace scenarios

Old logs:-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK fn=smack_ptrace_access_check action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
ocomm="tst_pt"
[  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK fn=smack_ptrace_traceme action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=12685 comm="tst_pt_me" opid=12563 
ocomm="bash"
[ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK fn=smack_bprm_set_creds action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=1778 comm="tst_bprm" opid=1776 
ocomm="tst_bprm"

New logs:-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK fn=smack_ptrace_access_check action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=5189 tracer-comm="tst_pt" pid=5189 
comm="tst_pt" tracee-pid=962 tracee-comm="test_tracee"
[  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK fn=smack_ptrace_traceme action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=6161 tracer-comm="bash" pid=6310 
comm="tst_pt_me" tracee-pid=6310 tracee-comm="tst_pt_me"
[ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK fn=smack_bprm_set_creds action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=6435 tracer-comm="tst_bprm" pid=6436 
comm="tst_bprm" tracee-pid=6436 tracee-comm="tst_bprm"

Signed-off-by: Vishal Goel 


What test case do you have that generates these records?



Added linux-audit to the CC list.


---
  include/linux/lsm_audit.h |  1 +
  security/lsm_audit.c  | 15 +++
  security/smack/smack.h    | 19 +++
  security/smack/smack_access.c | 16 
  security/smack/smack_lsm.c    | 33 ++---
  5 files changed, 73 insertions(+), 11 deletions(-)

diff --git a/include/linux/lsm_audit.h b/include/linux/lsm_audit.h
index 17d02eda9..6d752ea16 100644
--- a/include/linux/lsm_audit.h
+++ b/include/linux/lsm_audit.h
@@ -76,6 +76,7 @@ struct common_audit_data {
  #define LSM_AUDIT_DATA_IBENDPORT 14
  #define LSM_AUDIT_DATA_LOCKDOWN 15
  #define LSM_AUDIT_DATA_NOTIFICATION 16
+#define LSM_AUDIT_DATA_PTRACE   17
  union {
  struct path path;
  struct dentry *dentry;
diff --git a/security/lsm_audit.c b/security/lsm_audit.c
index 1897cbf6f..069e0282c 100644
--- a/security/lsm_audit.c
+++ b/security/lsm_audit.c
@@ -318,6 +318,21 @@ static void dump_common_audit_data(struct audit_buffer *ab,
  }
  break;
  }
+    case LSM_AUDIT_DATA_PTRACE: {
+    struct task_struct *tsk = a->u.tsk;
+    if (tsk) {
+    pid_t pid = task_tgid_nr(tsk);
+
+    if (pid) {
+    char comm[sizeof(tsk->comm)];
+
+    audit_log_format(ab, " tracee-pid=%d tracee-comm=", pid);
+    audit_log_untrustedstring(ab,
+    memcpy(comm, tsk->comm, sizeof(comm)));
+    }
+    }
+    break;
+    }
  case LSM_AUDIT_DATA_NET:
  if (a->u.net->sk) {
  const struct sock *sk = a->u.net->sk;
diff --git a/security/smack/smack.h b/security/smack/smack.h
index 99c342259..901228205 100644
--- a/security/smack/smack.h
+++ b/security/smack/smack.h
@@ -266,6 +266,7 @@ struct smack_audit_data {
  char *object;
  char *request;
  int result;
+    struct task_struct *tracer_tsk;
  };
    /*
@@ -497,6 +498,16 @@ static inline void smk_ad_setfield_u_net_sk(struct 
smk_audit_info *a,
  {
  a->a.u.net->sk = sk;
  }
+static inline void smk_ad_setfield_u_tracer(struct smk_audit_info *a,
+    struct task_struct *t)
+{
+   a->a.smack_audit_data->tracer_tsk = t;
+}
+static inline void smk_ad_setfield_u_tracee(struct smk_audit_info *a,
+    struct task_struct *t)
+{
+   a->a.u.tsk = t;
+}
    #else /* no AUDIT */
  @@ -524,6 +535,14 @@ static inline void smk_ad_setfield_u_net_sk(struct 
smk_audit_info *a,
  struct sock *sk)
  {
  }
+static inline void smk_ad_setfield_u_tracer(struct smk_audit_info *a,
+    struct task_struct *t)
+{
+}
+static inline void smk_ad_setfield_u_tracee(struct smk_audit_info *a,
+    struct task_struct *t)
+{
+}
  #endif
    #endif  /* _SECURITY_SMACK_H */
diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c
index d2186e275..f39e3ac92 

Re: [PATCH 1/1] Smack:- Fix the issue of wrong info printed in ptrace error logs

2021-12-20 Thread Casey Schaufler

On 12/20/2021 2:13 AM, Vishal Goel wrote:

Currently tracer process info is printed in object field in
smack error log for ptrace check which is wrong.
Object process should print the tracee process info.
Tracee info is not printed in the smack error logs.
So it is not possible to debug the ptrace smack issues.

Now changes has been done to print both tracer and tracee
process info in smack error logs for ptrace scenarios

Old logs:-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK fn=smack_ptrace_access_check action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=9397 comm="tst_pt" opid=9397 
ocomm="tst_pt"
[  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK fn=smack_ptrace_traceme action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=12685 comm="tst_pt_me" opid=12563 
ocomm="bash"
[ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK fn=smack_bprm_set_creds action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= pid=1778 comm="tst_bprm" opid=1776 
ocomm="tst_bprm"

New logs:-
[  378.098330] audit: type=1400 audit(1637212273.300:2): lsm=SMACK fn=smack_ptrace_access_check action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=5189 tracer-comm="tst_pt" pid=5189 
comm="tst_pt" tracee-pid=962 tracee-comm="test_tracee"
[  520.261605] audit: type=1400 audit(1637212415.464:3): lsm=SMACK fn=smack_ptrace_traceme action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=6161 tracer-comm="bash" pid=6310 
comm="tst_pt_me" tracee-pid=6310 tracee-comm="tst_pt_me"
[ 1445.259319] audit: type=1400 audit(1637213340.460:5): lsm=SMACK fn=smack_bprm_set_creds action=denied 
subject="Tracer_lbl" object="Tracee_lbl" requested= tracer-pid=6435 tracer-comm="tst_bprm" pid=6436 
comm="tst_bprm" tracee-pid=6436 tracee-comm="tst_bprm"

Signed-off-by: Vishal Goel 


Added linux-audit to the CC list.


---
  include/linux/lsm_audit.h |  1 +
  security/lsm_audit.c  | 15 +++
  security/smack/smack.h| 19 +++
  security/smack/smack_access.c | 16 
  security/smack/smack_lsm.c| 33 ++---
  5 files changed, 73 insertions(+), 11 deletions(-)

diff --git a/include/linux/lsm_audit.h b/include/linux/lsm_audit.h
index 17d02eda9..6d752ea16 100644
--- a/include/linux/lsm_audit.h
+++ b/include/linux/lsm_audit.h
@@ -76,6 +76,7 @@ struct common_audit_data {
  #define LSM_AUDIT_DATA_IBENDPORT 14
  #define LSM_AUDIT_DATA_LOCKDOWN 15
  #define LSM_AUDIT_DATA_NOTIFICATION 16
+#define LSM_AUDIT_DATA_PTRACE   17
union   {
struct path path;
struct dentry *dentry;
diff --git a/security/lsm_audit.c b/security/lsm_audit.c
index 1897cbf6f..069e0282c 100644
--- a/security/lsm_audit.c
+++ b/security/lsm_audit.c
@@ -318,6 +318,21 @@ static void dump_common_audit_data(struct audit_buffer *ab,
}
break;
}
+   case LSM_AUDIT_DATA_PTRACE: {
+   struct task_struct *tsk = a->u.tsk;
+   if (tsk) {
+   pid_t pid = task_tgid_nr(tsk);
+
+   if (pid) {
+   char comm[sizeof(tsk->comm)];
+
+   audit_log_format(ab, " tracee-pid=%d 
tracee-comm=", pid);
+   audit_log_untrustedstring(ab,
+   memcpy(comm, tsk->comm, sizeof(comm)));
+   }
+   }
+   break;
+   }
case LSM_AUDIT_DATA_NET:
if (a->u.net->sk) {
const struct sock *sk = a->u.net->sk;
diff --git a/security/smack/smack.h b/security/smack/smack.h
index 99c342259..901228205 100644
--- a/security/smack/smack.h
+++ b/security/smack/smack.h
@@ -266,6 +266,7 @@ struct smack_audit_data {
char *object;
char *request;
int result;
+   struct task_struct *tracer_tsk;
  };
  
  /*

@@ -497,6 +498,16 @@ static inline void smk_ad_setfield_u_net_sk(struct 
smk_audit_info *a,
  {
a->a.u.net->sk = sk;
  }
+static inline void smk_ad_setfield_u_tracer(struct smk_audit_info *a,
+struct task_struct *t)
+{
+   a->a.smack_audit_data->tracer_tsk = t;
+}
+static inline void smk_ad_setfield_u_tracee(struct smk_audit_info *a,
+struct task_struct *t)
+{
+   a->a.u.tsk = t;
+}
  
  #else /* no AUDIT */
  
@@ -524,6 +535,14 @@ static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,

struct sock *sk)
  {
  }
+static inline void smk_ad_setfield_u_tracer(struct smk_audit_info *a,
+   struct task_struct *t)
+{
+}
+static inline void smk_ad_setfield_u_tracee(struct smk_audit_info *a,
+   struct task_struct *t)
+{