From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E988C5DF60 for ; Fri, 8 Nov 2019 04:56:39 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 82AFA21848 for ; Fri, 8 Nov 2019 04:56:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=dke-khu-ac-kr.20150623.gappssmtp.com header.i=@dke-khu-ac-kr.20150623.gappssmtp.com header.b="thzANrCe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 82AFA21848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=dke.khu.ac.kr Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.92.3) (envelope-from ) id 1iSwJc-0002w6-91; Thu, 07 Nov 2019 23:56:08 -0500 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.3) (envelope-from ) id 1iSwJY-0002vf-Rk for kernelnewbies@kernelnewbies.org; Thu, 07 Nov 2019 23:56:05 -0500 Received: by mail-lf1-x132.google.com with SMTP id f24so385095lfh.10 for ; Thu, 07 Nov 2019 20:56:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dke-khu-ac-kr.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=a0+zy04wAK7zkjbYjZuq+LmE3a5KmM5xqJRvRYShCV8=; b=thzANrCeXXTlKxtRqHGZHkWFEBd/Cw27FLSCEZvEc60T694CjMIdu5Y1NtgKqT5zeC vpcaYQwigje91nbarnzPegHVBuJ0qE+r+wHuNUwWkDO7EO0zKbnlKSwMmz8pWL1nOHSh yc09yUFLjbnyyZB2MzYPrj7iYuvGvID6otjsWJtTrmeXvLVYF3zeSOP10GvggLs8woe7 tkB9cRzbhlNJyJ6VaZWkaSy+/6ayr4JQsBF/PNbLGC3T3t3DoVwC9ZAKRkt8W48XdfB0 8I1fHe3EafjZ0hm94U+VtJfnAqSsNF23ypX97GSlxNUGxJjsWJJ8ARBmSrPw8t6stzuL Bq5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=a0+zy04wAK7zkjbYjZuq+LmE3a5KmM5xqJRvRYShCV8=; b=KNMIChp0ItDRUmTnPGuwdgCuhc4cxTeNrkhhYupPtlzIyu28YAJzE1iJuL9W0f7CT2 K7M/qUCao7O2MiaFmyjsTV6cJEmm5o10njSzYgMthIau5eubmy6LH8gIb3T1W2eiyFrT cn5rWmkc35NKlV4Bx46NxrNph57IocB1KUex02TK9LO3o09Beuh4P1jqwXSfH4LDed8I u40kptYMY8vJfeWFWMM83qnL5UrLsRVabtg2+ECUVb3iLboAvL6skU+Qh28UPxG1lTKo NULzICFiibmXtkWnt5tZAlxuek24WpS8irIY2FvUWnENsdKGHyWKE/muhbBDOBJimjG6 3JOA== X-Gm-Message-State: APjAAAXJLkPPV9AXvWQ3oR4rTPNZcByhou1IzPSJr6z8Qmy/XibP9D5Z gGkPHJZuCYnorKH/CduVvGJeWykm+hVWaqvRMha6NQ== X-Google-Smtp-Source: APXvYqwUG+A6GTVs8fYKNmfTr3/fCojtSq9nDMD8WHHnCui6MDodNrQM3p3M+6ZRdwKtCVRhte6pG5HbWIheCYYF+kE= X-Received: by 2002:a19:dc56:: with SMTP id f22mr4841962lfj.43.1573188899489; Thu, 07 Nov 2019 20:54:59 -0800 (PST) MIME-Version: 1.0 References: <694299.1571809092@turing-police> <20191105072232.GC2587462@kroah.com> <219753.1572950606@turing-police> In-Reply-To: <219753.1572950606@turing-police> From: =?UTF-8?B?SXJmYW4gVWxsYWggKOyauOudvCDsnbTrpbTtjJAp?= Date: Fri, 8 Nov 2019 13:54:47 +0900 Message-ID: Subject: Re: Netlink socket returns NULL in vmx.c kernel file To: =?UTF-8?Q?Valdis_Kl=C4=93tnieks?= Cc: Greg KH , Linux Kernel List X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============4134162864168594030==" Errors-To: kernelnewbies-bounces@kernelnewbies.org --===============4134162864168594030== Content-Type: multipart/alternative; boundary="00000000000084df650596ce9516" --00000000000084df650596ce9516 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you very much. I am trying to rewrite the code. and fix these issues. On Tue, Nov 5, 2019 at 7:43 PM Valdis Kl=C4=93tnieks wrote: > On Tue, 05 Nov 2019 17:59:43 +0900, Irfan Ullah said: > > > Thank you for the response. > > Attached are the files for kernel-user spaces communication. > > > //when I remove this wait the code does not work > > msleep(3000); > > If your code doesn't work, but sticking in random delays makes > it start working, you almost certainly have a race condition or > synchronization issue that should be fixed using proper locking. > > > void hello_exit(void) > > { > > //netlink_kernel_release(nl_sk); > > Congratulations. You just leaked a socket here, which is going to > make it difficult to use that socket until you either reboot or find a > way to close it properly before trying to create it again. > > > (code generates some warnings, but it is not severe and could be ignore= d > for the time being). > > You should do the following: > 1) Understand your code well enough so you understand *why* the compiler > issued the warning. > 2) Correct your code so the compiler doesn't complain. It almost certainl= y > understands C better than you do. > > gcc 9.2.1 emits one warning on the kernel module code at default warning > levels. And it's one you *really* need to fix, because it indicates that > you > and the compiler are not on the same page about what types your variables > are. > Since it's going to go ahead and generate code based on what types *it* > thinks > your variables are, you will have nothing but pain and anguish debugging = if > you thought they were some other type.... > > In fact, you may want to compile the kernel module with 'make W=3D1' to g= et > more > warnings. If your system has sparse, you should use 'make W=3D1 C=3D1'. > > And all the warnings this generates are things that shouldn't be seen in > clean > kernel code. > > I didn't bother looking closely at your userspace. I gave up > when I saw this: > > 14 int sock_fd; > (...) > 68 void user_space_receiver() > 69 { > (...) > 96 user_space_receiver(sock_fd); > > There's 2 basic ways to pass a variable to a function. You're trying > to use both of them here. Pick one and use it properly. > > Oh - and there's no possible way to reach the close(sock_fd); on line > 77, because the rest of the function infinite loops without a break. At > the > very least, you should be checking the return code from recvmsg() and > exiting the while(1) loop if there's an issue. > > Bottom line: You need to get a *lot* more experience writing proper > C code in userspace before you try to write kernel code. > --=20 *Best Regards,* *Mr. Irfan Ullah* PhD Candidate Data and Knowledge Engineering(DKE) Lab Department of Computer Science and Engineering Kyung Hee University, South Korea. +82-010-591-51651 <+82%2010-3877-8867> sahibzada.iu@gmail.com sahibzada_irfanullah --00000000000084df650596ce9516 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thank you very much. I am trying=C2=A0to rewrite the code.= and fix these issues.=C2=A0

On Tue, Nov 5, 2019 at 7:43 PM Valdis Kl=C4= =93tnieks <valdis.kletnieks@v= t.edu> wrote:
On Tue, 05 Nov 2019 17:59:43 +0900, Irfan Ullah said:

> Thank you for the response.
> Attached are the files for kernel-user spaces communication.

>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0//when I remove = this wait the code does not work
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0msleep(3000);
If your code doesn't work, but sticking in random delays makes
it start working, you almost certainly have a race condition or
synchronization issue that should be fixed using proper locking.

> void hello_exit(void)
> {
>=C2=A0 =C2=A0 =C2=A0 =C2=A0//netlink_kernel_release(nl_sk);

Congratulations. You just leaked a socket here, which is going to
make it difficult to use that socket until you either reboot or find a
way to close it properly before trying to create it again.

> (code generates some warnings, but it is not severe and could be ignor= ed for the time being).

You should do the following:
1) Understand your code well enough so you understand *why* the compiler issued the warning.
2) Correct your code so the compiler doesn't complain. It almost certai= nly
understands C better than you do.

gcc 9.2.1 emits one warning on the kernel module code at default warning levels.=C2=A0 And it's one you *really* need to fix, because it indicat= es that you
and the compiler are not on the same page about what types your variables a= re.
Since it's going to go ahead and generate code based on what types *it*= thinks
your variables are, you will have nothing but pain and anguish debugging if=
you thought they were some other type....

In fact, you may want to compile the kernel module with 'make W=3D1'= ; to get more
warnings.=C2=A0 If your system has sparse, you should use 'make W=3D1 C= =3D1'.

And all the warnings this generates are things that shouldn't be seen i= n clean
kernel code.

I didn't bother looking closely at your userspace.=C2=A0 I gave up
when I saw this:

=C2=A0 =C2=A0 =C2=A014 int sock_fd;
(...)
=C2=A0 =C2=A0 =C2=A068 void user_space_receiver()
=C2=A0 =C2=A0 =C2=A069 {
(...)
=C2=A0 =C2=A0 =C2=A096=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0user_space_receiver(sock_fd);

There's 2 basic ways to pass a variable to a function. You're tryin= g
to use both of them here.=C2=A0 Pick one and use it properly.

Oh - and there's no possible way to reach the close(sock_fd); on line 77, because the rest of the function infinite loops without a break.=C2=A0 = At the
very least, you should be checking the return code from recvmsg() and
exiting the while(1) loop if there's an issue.

Bottom line:=C2=A0 You need to get a *lot* more experience writing proper C code in userspace before you try to write kernel code.


--
Best Regards,


Mr. Irfan Ullah
PhD Candidate
Data and Knowledge Engineering(DKE) Lab
Department of Computer Science and Engineering
Kyung Hee University, South Korea.
=C2=A0+82-010-591-51651
=C2=A0sahibzada_irfanulla= h
--00000000000084df650596ce9516-- --===============4134162864168594030== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============4134162864168594030==--