Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp175987iob; Tue, 3 May 2022 14:24:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjPQLPjNTmFjRvfI4tIBHpybiAT6wNke4XpCSdZgkBJMH4amOHzWTepQ/FDqOjHX35mmGe X-Received: by 2002:a17:90b:3806:b0:1d2:6e95:f5cc with SMTP id mq6-20020a17090b380600b001d26e95f5ccmr6967398pjb.23.1651613085062; Tue, 03 May 2022 14:24:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651613085; cv=none; d=google.com; s=arc-20160816; b=yHrKlnfUjLah+atG5ACcsWPYqhqlYW0NW9g4Zs2uumRpmYrtQT8PnLsexWc8hV7l6H CTVCzeMijFynTYUDKdW3EaFAxonZnQB0n0j6cvCBJqGqL42K3qMwkc5pNWVh6nZWyZBf f6eV0qgFyu30jrSKp9XQTwccPBb2WOfTle8lLJ+9rbIf9E+oRESKIvx4qD2YrtZD7+ve jCQWDAaUQyfS6Mu5vubBJqHbzceLiMuD4pWKuwDnbuAdlA1OTk2SXW6bWm4k+Zj6DhCS AGM0YupPTsBFvxYupaegGaO770KvJ3sKG8NsSFt4gd1WKN9YyLZ550KgeRqH2uQBYfoh QHFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=h9qkGkLhyYVuP5NA+EyqoC9Fx6dLw0IZC0J4czMcE3s=; b=gglbtYe1GslO+Auo2zrW0nC8PY+PmLPyjU1xJ8cOqeDmQPcxq+WBBku+e+mvSMCKRr 7n8jdHRSa3rOtj69GITPLk5QbLUlWbLw1gwS9ZZDEQtyYKPF9sapDU30mUQ/kN8w80mj 91WjA960UAFnQfGK3ilGqWYylo1KKQyb+Tv9//X2DVZJpKjqwfSJp9lMwDrP+LsrJgid c9haOdRQqX14JbKmq2ZouXGE6a1CF+Jk5cOawHIJwOKktFKEFE3FyRs8eRbHcBiV598f XUU+Xb7EXlswDK9yWSiqsQBiMzUXxLlQLp5Jt9KEyA5IUiRb4gNwhF8FKgiakEC2rtrn jKjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20210112.gappssmtp.com header.s=20210112 header.b=Q3kJ8dp+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020a63ae04000000b0039e44e45e87si18744940pgf.485.2022.05.03.14.24.27; Tue, 03 May 2022 14:24:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore-com.20210112.gappssmtp.com header.s=20210112 header.b=Q3kJ8dp+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238649AbiECQLe (ORCPT + 99 others); Tue, 3 May 2022 12:11:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239024AbiECQLb (ORCPT ); Tue, 3 May 2022 12:11:31 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF9452B24C for ; Tue, 3 May 2022 09:07:57 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id j15so24070136wrb.2 for ; Tue, 03 May 2022 09:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=h9qkGkLhyYVuP5NA+EyqoC9Fx6dLw0IZC0J4czMcE3s=; b=Q3kJ8dp+glqL6hrMCvTstBZwmmJPz/CaYGwV/d2xk6xJBAeFfuS9shb832MfGT6Fuq vl08vQTfs4UHQQYYc2UqZf11rgvLU2YvesaMJS5RhCFvNtiW/pwTuiUcPd8Peko6upbq bHB3lt95E7lnHd4R9BBM5jhWGwQ/hlmhJJyqo5l7uNoZQ+IFVLKmDYf5sL+TXof0K0zA JQG/IG5XHWr2bomNbJy5JvGUXC9dBXVhCJnoETdpR6S/zBanM7P/cWxwq81aSLeonEYq /e3VP5qHvXG7fDN198EXXI2Gl3Pfu9oKifURmXEGQHlInf/4en50cV/cARyn9fdyaYs0 0PKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=h9qkGkLhyYVuP5NA+EyqoC9Fx6dLw0IZC0J4czMcE3s=; b=ZtIMUPOf92Jp1p4nDIK7wtKiukDnMf5h3VJbykCJudYqD/X2q6T1pxP20i7l0zlU1b ln/547G2g17b+WysWXPt9Ckci7OTaHvoMMFlSKhGtg8Hy5b7GQRfaK7DkVeVJd1bezja eeQP1uupinld8my+ZH0cCYPmND8dTktA3dEF106aXQpsfjxYHIQftTyHIAu+fKM5Q7SX u3oBbDD0xmrA5uwKpog40y2R4TIkZ3KIt/KJkYPzDdjWLveKzvVn2RNhWsy3uYFCblWq Os1eFmolOATAqK0SFRVT1F5gMeC2wIJzGSDoctjTYJ/Bj0GW6wr2DgC530ifzrrMvcRq kKXA== X-Gm-Message-State: AOAM533m6c0b6cF0Sx3YBtmeCs0a0hDZCDmGs/ISFYZGYVN04syWWdXr xG2LMU8XB4FrToHBmYRcW0DY2qFJDEErrbOV2uCD X-Received: by 2002:a05:6000:80e:b0:20c:5b45:a700 with SMTP id bt14-20020a056000080e00b0020c5b45a700mr9669529wrb.662.1651594076393; Tue, 03 May 2022 09:07:56 -0700 (PDT) MIME-Version: 1.0 References: <20220503090212.1322050-1-svens@linux.ibm.com> In-Reply-To: <20220503090212.1322050-1-svens@linux.ibm.com> From: Paul Moore Date: Tue, 3 May 2022 12:07:45 -0400 Message-ID: Subject: Re: [PATCH 1/2] audit: add call argument to socketcall auditing To: Sven Schnelle Cc: Eric Paris , linux-audit@redhat.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 3, 2022 at 5:02 AM Sven Schnelle wrote: > > socketcall auditing misses the call argument: > > type=SOCKETCALL msg=audit: nargs=3 a0=10 a1=3 a2=c > > which renders socketcall auditing (almost) useless. Add the call > argument so it is possible to decode the actual syscall from the > audit log: > > type=SOCKETCALL msg=audit: call=1 nargs=3 a0=10 a1=3 a2=c > > Signed-off-by: Sven Schnelle > --- > include/linux/audit.h | 10 +++++----- > kernel/audit.h | 1 + > kernel/auditsc.c | 6 ++++-- > net/compat.c | 2 +- > net/socket.c | 2 +- > 5 files changed, 12 insertions(+), 9 deletions(-) Hi Sven, Thanks for catching this, my only guess is that the original code assumed that a0 held the socket call number. In addition to the kernel test robot errors that need fixing, I've made some comments inline with the patch below ... > diff --git a/kernel/audit.h b/kernel/audit.h > index 58b66543b4d5..34e53b6f0ebb 100644 > --- a/kernel/audit.h > +++ b/kernel/audit.h > @@ -153,6 +153,7 @@ struct audit_context { > int type; > union { > struct { > + int call; > int nargs; > long args[6]; Not your code, but while you are making changes, perhaps make @args[6] and unsigned long to match the network stack's code. > } socketcall; > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > index ea2ee1181921..c856893041c9 100644 > --- a/kernel/auditsc.c > +++ b/kernel/auditsc.c > @@ -1399,8 +1399,9 @@ static void show_special(struct audit_context *context, int *call_panic) > switch (context->type) { > case AUDIT_SOCKETCALL: { > int nargs = context->socketcall.nargs; > + int call = context->socketcall.call; > > - audit_log_format(ab, "nargs=%d", nargs); > + audit_log_format(ab, "call=%d nargs=%d", call, nargs); > for (i = 0; i < nargs; i++) > audit_log_format(ab, " a%d=%lx", i, > context->socketcall.args[i]); The approach we take when adding new fields to existing audit records is to add them to the end of the record. Using your example in the patch description, we would want to see the following record format for SOCKETCALL: type=SOCKETCALL msg=audit: nargs=3 a0=10 a1=3 a2=c call=1 > @@ -2684,13 +2685,14 @@ void __audit_bprm(struct linux_binprm *bprm) > * @args: args array > * > */ > -int __audit_socketcall(int nargs, unsigned long *args) > +int __audit_socketcall(int call, int nargs, unsigned long *args) > { > struct audit_context *context = audit_context(); > > if (nargs <= 0 || nargs > AUDITSC_ARGS || !args) > return -EINVAL; > context->type = AUDIT_SOCKETCALL; > + context->socketcall.call = call; > context->socketcall.nargs = nargs; > memcpy(context->socketcall.args, args, nargs * sizeof(unsigned long)); > return 0; > diff --git a/net/compat.c b/net/compat.c > index 210fc3b4d0d8..0df955019ecc 100644 > --- a/net/compat.c > +++ b/net/compat.c > @@ -437,7 +437,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args) > if (copy_from_user(a, args, len)) > return -EFAULT; > > - ret = audit_socketcall_compat(len / sizeof(a[0]), a); > + ret = audit_socketcall_compat(call, len / sizeof(a[0]), a); See my note below for the non-compat version of socketcall(2). > diff --git a/net/socket.c b/net/socket.c > index 6887840682bb..ff71f28c96f7 100644 > --- a/net/socket.c > +++ b/net/socket.c > @@ -2921,7 +2921,7 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args) > if (copy_from_user(a, args, len)) > return -EFAULT; > > - err = audit_socketcall(nargs[call] / sizeof(unsigned long), a); > + err = audit_socketcall(call, nargs[call] / sizeof(unsigned long), a); I recognize that this isn't your code, but I think it might be better to cleanup the arg count calculation passed as the second parameter. Something like this not only looks cleaner, but it should be a bit more robust against other kernel changes: err = audit_socketcall(call, len / AL(1), a); ... it may also help resolve some of the kernel test robot errors you are seeing. -- paul-moore.com