Date: Wed, 28 Aug 2019 10:10:35 -0700 From: Maksim Yevmenkin <maksim.yevmenkin@gmail.com> To: "mms.vanbreukelingen@gmail.com" <mms.vanbreukelingen@gmail.com> Cc: "kostikbel@gmail.com" <kostikbel@gmail.com>, Warner Losh <imp@bsdimp.com>, Hans Petter Selasky <hps@selasky.org>, "freebsd-current@freebsd.org" <freebsd-current@freebsd.org> Subject: Re: Kernel-Crash when working with ubt0 Message-ID: <CAFPOs6oUiFrgdFFS2EWPVzFkGfZsntk3JYPDE_2VgLoW7B4BuA@mail.gmail.com> In-Reply-To: <CAFPOs6o6yHkC4xXnYBTD4QvUJryb=_bBKeJA5YKWG-No6kdtVQ@mail.gmail.com> References: <47509401.1440476.1566796167857.ref@mail.yahoo.com> <47509401.1440476.1566796167857@mail.yahoo.com> <5aa8faeb-5e8e-38be-4301-81f3d82c494a@selasky.org> <CANCZdfpJARVFz%2BCyvbAK9sH4E6__DPAunYQz5rxexO-mzuvsuw@mail.gmail.com> <00E772F0-7231-44C4-B314-26730CC7DF21@gmail.com> <20190827071052.GT71821@kib.kiev.ua> <233039408.1857163.1566892977201@mail.yahoo.com> <CAFPOs6o6yHkC4xXnYBTD4QvUJryb=_bBKeJA5YKWG-No6kdtVQ@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--0000000000004eb85005913078ec Content-Type: text/plain; charset="UTF-8" > > > Hmm... interesting.... > > > > > > I only took a brief look at it. I suppose I can ensure user space address is wired and then copyout() can be called with mutex held > > > > >No, you cannot do this, at least without making the kernel to panic. > > User might unmap the wired mapping at any time still. > > Kostik, > > i was thinking along the lines of vslock/vsunlock and copyout_nofault. > basically similar to the sysctl code. do you think this would not > work? actually, i dont think i need to hold lock over copyout. attached is my version of the patch (untested) thanks, max --0000000000004eb85005913078ec Content-Type: text/plain; charset="US-ASCII"; name="ng_btsocket_hci_raw.c.diff.txt" Content-Disposition: attachment; filename="ng_btsocket_hci_raw.c.diff.txt" Content-Transfer-Encoding: base64 Content-ID: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LT5wY2JfbXR4KTsKKwkJCXJldHVybiAoZXJyb3IpOwor CQl9CiAKLQkJaWYgKHBjYi0+bXNnICE9IE5VTEwgJiYgcGNiLT5tc2ctPmhlYWRlci5jbWQgPT0g TkdNX0xJU1ROQU1FUykgeworCQltc2cgPSBwY2ItPm1zZzsKKwkJcGNiLT5tc2cgPSBOVUxMOwor CisJCW10eF91bmxvY2soJnBjYi0+cGNiX210eCk7CisKKwkJaWYgKG1zZyAhPSBOVUxMICYmIG1z Zy0+aGVhZGVyLmNtZCA9PSBOR01fTElTVE5BTUVTKSB7CiAJCQkvKiBSZXR1cm4gZGF0YSBiYWNr IHRvIHVzZXIgc3BhY2UgKi8KLQkJCXN0cnVjdCBuYW1lbGlzdAkqbmwxID0gKHN0cnVjdCBuYW1l bGlzdCAqKSBwY2ItPm1zZy0+ZGF0YTsKKwkJCXN0cnVjdCBuYW1lbGlzdAkqbmwxID0gKHN0cnVj dCBuYW1lbGlzdCAqKSBtc2ctPmRhdGE7CiAJCQlzdHJ1Y3Qgbm9kZWluZm8JKm5pMSA9ICZubDEt Pm5vZGVpbmZvWzBdOwogCiAJCQl3aGlsZSAobmwtPm51bV9uYW1lcyA+IDAgJiYgbmwxLT5udW1u YW1lcyA+IDApIHsKQEAgLTEzODUsOCArMTQwOSw5IEBACiAJCX0gZWxzZQogCQkJZXJyb3IgPSBF SU5WQUw7CiAKLQkJTkdfRlJFRV9NU0cocGNiLT5tc2cpOyAvKiBjaGVja3MgZm9yICE9IE5VTEwg Ki8KLQkJfSBicmVhazsKKwkJTkdfRlJFRV9NU0cobXNnKTsgLyogY2hlY2tzIGZvciAhPSBOVUxM ICovCisJCXJldHVybiAoZXJyb3IpOworCQl9IC8qIE5PVFJFQUNIRUQgKi8KIAogCWRlZmF1bHQ6 CiAJCWVycm9yID0gRUlOVkFMOwo= --0000000000004eb85005913078ec--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFPOs6oUiFrgdFFS2EWPVzFkGfZsntk3JYPDE_2VgLoW7B4BuA>