From nobody Mon Sep 18 21:38:18 2023 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RqJ7g6Q8Dz4tnLP for ; Mon, 18 Sep 2023 21:38:23 +0000 (UTC) (envelope-from yuri@aetern.org) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4RqJ7g2qHKz4ZMg for ; Mon, 18 Sep 2023 21:38:23 +0000 (UTC) (envelope-from yuri@aetern.org) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=aetern.org header.s=fm1 header.b=uAUnUBwd; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="C XGuWEh"; spf=pass (mx1.freebsd.org: domain of yuri@aetern.org designates 66.111.4.25 as permitted sender) smtp.mailfrom=yuri@aetern.org Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 70BE75C01CE for ; Mon, 18 Sep 2023 17:38:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 18 Sep 2023 17:38:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aetern.org; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm1; t= 1695073102; x=1695159502; bh=eiTNCJtdQCVL4YoPTc+9Gxd4JfEUVk8hgi1 Df2JlZcc=; b=uAUnUBwd3PdDAcHaIDdgKRKze9KoyLeIi38PxaU4r1NULDvQgLA 9uMOZHctLgWQvoDqMyVOoZPhOrnp6ueENPJ1bysSWM+v7D73E2SEeUKhkqvjwE/Z Y6oi1Opu1FxDupB+k95fV4SB+Q2XhBFAcqmfL8vYaWpy6T130Y494Yc21lL1/LZp lDVpW7xab+s165iYuZ+Or4HWGUIIv6XvofvWaVt3Eo66mXOfgM3zeCi1D58CMn6g iUFZm4UsKE/GDR01CEzNBVbw+rw8wqel1RJuiXZDn6ppVa+L7GQEzhdERgvKLr5c xltZfESeTYBpJ7RQcDuqNw4tbUCeTPdwcrg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1695073102; x= 1695159502; bh=eiTNCJtdQCVL4YoPTc+9Gxd4JfEUVk8hgi1Df2JlZcc=; b=C XGuWEhY7VJ34hidd3NK4WVKTi2ZLLrW+5KDOkt3ECKsvLQgCgsOxhyvD+jLCuD9D MrFO6Iquago3olstDQxKAIDwWmNckmBtQ/j2Kvs2ufQ0k0yIzmYvTIApcSa+Fl46 Zh0KHwnlFaUppQm8BXcFg6cNf5TQXicISa9mVhicEYu0Q80/dXfrAWJ7BzJjOyC4 Urgj7L8AW3n+0THhsDAf6DfOBjxLPrbPuISTjKbq2ExXETn6qBHw03JOFViDi7xB BijOHm7ljVZsy83CttfiKPxnxLFPAW2Y3F3sno8OILxPfHeKfYISbMSVzyXmL/E1 DoNZBXpGlYqcyYOlDc1Uw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudejlecutefuodetggdotefrodftvfcurf hrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthejredttd dvjeenucfhrhhomhepjghurhhiuceohihurhhisegrvghtvghrnhdrohhrgheqnecuggft rfgrthhtvghrnhepkefhgfetfffgleetvdeiudeijefgffefhfffffehieetkeetvdehff evveevveffnecuffhomhgrihhnpehfrhgvvggsshgurdhorhhgpdhkmhhougdrmhhknecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhephihurhhise grvghtvghrnhdrohhrgh X-ME-Proxy: Feedback-ID: i0d79475b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 18 Sep 2023 17:38:21 -0400 (EDT) Message-ID: <36d29d5c-43cd-4e77-9406-e786d08a79e2@aetern.org> Date: Mon, 18 Sep 2023 23:38:18 +0200 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Error while building a kernel module with mkdir(2) Content-Language: en-US To: freebsd-hackers@freebsd.org References: From: Yuri In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spamd-Bar: / X-Rspamd-Pre-Result: action=no action; module=multimap; Matched map: local_wl_from X-Spamd-Result: default: False [-0.39 / 15.00]; R_DKIM_ALLOW(-0.20)[aetern.org:s=fm1,messagingengine.com:s=fm2]; R_SPF_ALLOW(-0.20)[+ip4:66.111.4.25]; XM_UA_NO_VERSION(0.01)[]; local_wl_from(0.00)[yuri@aetern.org]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; FREEFALL_USER(0.00)[yuri]; DKIM_TRACE(0.00)[aetern.org:+,messagingengine.com:+]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; ASN(0.00)[asn:19151, ipnet:66.111.4.0/24, country:US] X-Rspamd-Queue-Id: 4RqJ7g2qHKz4ZMg Rocky Hotas wrote: > Hello! > I hope this is the right ML to discuss about this issue. I am trying to > build the example kernel module presented in paragraph 2.1 of > > Designing BSD Rootkits: An Introduction to Kernel Hacking > by Joseph Kong > > However, I get this error: > > mkdir_hook.c:42:9: error: implicit declaration of function 'mkdir' is invalid in C99 [-Werror,-Wimplicit-function-declaration] > return(mkdir(td, syscall_args)); > ^ > mkdir_hook.c:57:45: error: use of undeclared identifier 'mkdir' > sysent[SYS_mkdir].sy_call = (sy_call_t *)mkdir; > > mkdir(2) requires `#include ' and I added it (while it was > not in the code from the book), but nothing changes. That include is for userland that needs mkdir(2). Your wrapper likely wants to override the in-kernel sys_mkdir() defined in . > What's still wrong? > > After this text, I paste the code and the Makefile (written following > https://docs.freebsd.org/en/books/arch-handbook/driverbasics/). > > Bye! > > Rocky > > > > === code: mkdir_hook.c === > > #include > #include /* defines used in kernel.h */ > #include > #include > #include > #include /* types used in module initialization */ > #include /* uprintf */ > #include > #include > #include /* mkdir(2) */ > > > /* mkdir system call hook. */ > static int > mkdir_hook(struct thread *td, void *syscall_args) > { > struct mkdir_args /* { > char *path; > int mode; > } */ *uap; > > uap = (struct mkdir_args *)syscall_args; > char path[255]; > size_t done; > int error; > error = copyinstr(uap->path, path, 255, &done); > > if (error != 0) > return(error); > /* Print a debug message. */ > uprintf("The directory \"%s\" will be created with the following" > " permissions: %o\n", path, uap->mode); > > return(mkdir(td, syscall_args)); > } > > /* The function called at load/unload. */ > static int > load(struct module *module, int cmd, void *arg) > { > int error = 0; > switch (cmd) { > case MOD_LOAD: > /* Replace mkdir with mkdir_hook. */ > sysent[SYS_mkdir].sy_call = (sy_call_t *)mkdir_hook; > break; > case MOD_UNLOAD: > /* Change everything back to normal. */ > sysent[SYS_mkdir].sy_call = (sy_call_t *)mkdir; > break; > > default: > error = EOPNOTSUPP; > break; > } > > return(error); > } > > static moduledata_t > mkdir_hook_mod = { > "mkdir_hook", /* module name */ > load, /* event handler */ > NULL /* extra data */ > }; > > DECLARE_MODULE(mkdir_hook, mkdir_hook_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); > > > > === Makefile === > > KMOD=mkdir_hook > SRCS=mkdir_hook.c > .include >