Commit Graph

16823 Commits

Author SHA1 Message Date
AnotherTest
9b69c73dfe LibC: Stub out semaphore.h 2021-02-15 17:32:56 +01:00
Brian Gianforcaro
7482cb6531 Kernel: Avoid some un-necessary copies coming from range based for loops
- The irq_controller was getting add_ref/released needlessly during enumeration.

- Used ranges were also getting needlessly copied.
2021-02-15 15:25:23 +01:00
Brian Gianforcaro
a5f879ea8c Base: Add a man page documenting security mitigations
Since so much work is being put into mitigations, I thought
it would be nice to track them all in one place. This is the
start of that document.
2021-02-15 15:25:01 +01:00
Andreas Kling
9efd80f100 LibJS: Use fabs() instead of abs() in JS::Value
abs() takes an int, so this would only work correctly for numbers
smaller than INT_MAX.
2021-02-15 13:58:24 +01:00
Brian Gianforcaro
566b916364 CMake: Add 'setup-and-run' target to perform all prereqs and run the image
Running 'ninja install && ninja image && ninja run` is kind of
annoying. I got tired, and came up with this instead, which does the
right thing and I don't have to type out the incantation.
2021-02-15 12:25:31 +01:00
Linus Groh
e8ff61e64b Ports: Document build_{all,installed}.sh 2021-02-15 11:46:36 +01:00
Brian Gianforcaro
96943ab07c Kernel: Initial integration of Kernel Address Sanitizer (KASAN)
KASAN is a dynamic analysis tool that finds memory errors. It focuses
mostly on finding use-after-free and out-of-bound read/writes bugs.

KASAN works by allocating a "shadow memory" region which is used to store
whether each byte of memory is safe to access. The compiler then instruments
the kernel code and a check is inserted which validates the state of the
shadow memory region on every memory access (load or store).

To fully integrate KASAN into the SerenityOS kernel we need to:

 a) Implement the KASAN interface to intercept the injected loads/stores.

      void __asan_load*(address);
      void __asan_store(address);

 b) Setup KASAN region and determine the shadow memory offset + translation.
    This might be challenging since Serenity is only 32bit at this time.

    Ex: Linux implements kernel address -> shadow address translation like:

      static inline void *kasan_mem_to_shadow(const void *addr)
      {
          return ((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT)
                  + KASAN_SHADOW_OFFSET;
      }

 c) Integrating KASAN with Kernel allocators.
    The kernel allocators need to be taught how to record allocation state
    in the shadow memory region.

This commit only implements the initial steps of this long process:
- A new (default OFF) CMake build flag `ENABLE_KERNEL_ADDRESS_SANITIZER`
- Stubs out enough of the KASAN interface to allow the Kernel to link clean.

Currently the KASAN kernel crashes on boot (triple fault because of the crash
in strlen other sanitizer are seeing) but the goal here is to just get started,
and this should help others jump in and continue making progress on KASAN.

References:
* ASAN Paper: https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/37752.pdf
* KASAN Docs: https://github.com/google/kasan
* NetBSD KASAN Blog: https://blog.netbsd.org/tnf/entry/kernel_address_sanitizer_part_3
* LWN KASAN Article: https://lwn.net/Articles/612153/
* Tracking Issue #5351
2021-02-15 11:41:53 +01:00
Tom
be48a89b35 WindowServer: Fix double click handling while using cursor tracking
We need to first deliver the mouse event and possibly the double click
event and record these facts. Then, we need to iterate all global
tracking listeners and deliver the mouse event (but not the double
click event) to any such listener, unless they already had these
events delivered.

Fixes #4703
2021-02-15 11:03:49 +01:00
Brian Gianforcaro
69df3cfae7 Kernel: Mark KBuffer and its getters as [[nodiscard]]
There is no reason to call a getter without observing the result, doing
so indicates an error in the code. Mark these methods as [[nodiscard]]
to find these cases.
2021-02-15 09:34:52 +01:00
Brian Gianforcaro
0cbede91b8 Kernel: Mark Lock getters as [[nodiscard]]
There is no reason to call a getter without observing the result, doing
so indicates an error in the code. Mark these methods as [[nodiscard]]
to find these cases.
2021-02-15 09:34:52 +01:00
Brian Gianforcaro
a75d7958cc Kernel: Mark UserOrKernelBuffer and it's getters as [[nodicard]]
`UserOrKernelBuffer` objects should always be observed when created, in
turn there is no reason to call a getter without observing the result.
Doing either of these indicates an error in the code. Mark these methods
as [[nodiscard]] to find these cases.
2021-02-15 09:34:52 +01:00
Brian Gianforcaro
01a66efe9d Kernel: Mark KResult getters as [[nodiscard]]
There is no reason to call a getter without observing the result, doing
so indicates an error in the code. Mark these methods as [[nodiscard]]
to find these cases.
2021-02-15 09:34:52 +01:00
Brian Gianforcaro
3356f438ca AK: Mark Optional getters as [[nodiscard]]
There is no reason to call a getter without observing the result, doing
so indicates an error in the code. Mark these methods as [[nodiscard]]
to find these cases.
2021-02-15 09:34:52 +01:00
Brian Gianforcaro
8752a27519 Kernel: Mark PhysicalAddress/VirtualAddress getters as [[nodiscard]]
There is no reason to call a getter without observing the result, doing
so indicates an error in the code. Mark these methods as [[nodiscard]]
to find these cases.
2021-02-15 09:34:52 +01:00
Brian Gianforcaro
d71e235894 Kernel: Mark more StdLib functions as [[nodiscard]]
In the never ending journey to catch bugs, mark more functions
as [[nodiscard]] to find incorrect call sites.
2021-02-15 09:34:52 +01:00
Sergey Bugaev
373d135e74 LookupServer: Implement a DNS server :^)
LookupServer can now itself server as a DNS server! To service DNS clients, it
uses the exact same lookup logic as it does for LibIPC clients. Namely, it will
synthesize records for data from /etc/hosts on its own (you can use this to
configure host names for your domain!), and forward other questions to
configured upstream DNS servers. On top of that, it implements its own caching,
so once a DNS resource record has been obtained from an upstream server,
LookupServer will cache it locally for faster future lookups.

The DNS server part of LookupServer is disabled by default, because it requires
you to run it as root (for it to bind to the port 53) and on boot, and we don't
want either by default. If you want to try it, modify SystemServer.ini like so:

[LookupServer]
Socket=/tmp/portal/lookup
SocketPermissions=666
Priority=low
KeepAlive=1
User=root
BootModes=text,graphical

and enable server mode in LookupServer.ini like so:

[DNS]
Nameservers=...
EnableServer=1

If in the future we implement socket takeover for IP sockets, these limitations
may be lifted.
2021-02-15 09:14:42 +01:00
Sergey Bugaev
bc05ab47de LibCore: Expose UDPServer::fd() and make the constructor protected 2021-02-15 09:14:42 +01:00
Sergey Bugaev
56831ed81f LookupServer: Misc tweaks 2021-02-15 09:14:42 +01:00
Sergey Bugaev
19cfed329e LookupServer: Make lookup() return DNSAnswer's instead of strings
This way, we propagate proper TTL. None of the callers currently care, though.
2021-02-15 09:14:42 +01:00
Sergey Bugaev
3fba6bfb5e LookupServer: Move cache check into the outer lookup() method
Where it belongs, alongside the /etc/hosts check. The inner lookup() method is
really about talking to a specific DNS server.

Also, don't bail out on a empty name. An empty DNSName is actually '.' — a
single dot — aka the DNS root.
2021-02-15 09:14:42 +01:00
Sergey Bugaev
af6aac8c55 LookupServer: Store /etc/hosts as Vector<DNSAnswer>
...just like we store m_lookup_cache, in other words.

This immediately lets us match on types: for instance we will now only resolve
1.0.0.127.in-addr.arpa to localhost if asked for type PTR, not for type A. In
the future, this could also let us have the same /etc/hosts name resolve
to *multiple* addresses.
2021-02-15 09:14:42 +01:00
Sergey Bugaev
e9387e43db LookupServer: Store DNSName's in HashMap's directly
DNSName can now take care of case conversion when comparing using traits.
It still intentionally doesn't implement operator ==; you have to explicitly
decide whether you want case-sensitive or case-insensitive comparison.

This change makes caches (and /etc/hosts) case-transparent: we will now match
domains if they're the same except for the case.
2021-02-15 09:14:42 +01:00
Sergey Bugaev
bacbde31f3 LookupServer: Move case randomization into DNSName
* DNSName knows how to randomize itself
* DNSPacket no longer constructs DNSQuestion instances, it receives an already
  built DNSQuestion and just adds it to the list
* LookupServer::lookup() explicitly calls randomize_case() if it needs to
  randomize the case.
2021-02-15 09:14:42 +01:00
Sergey Bugaev
89f718c4c5 LookupServer: Don't cache DNS questions
We should only cache RRs (which we represent as instances of DNSAnswer), now
which questions generated them.
2021-02-15 09:14:42 +01:00
Sergey Bugaev
80f7489df0 LookupServer: Fix serializing name data in DNS answers
When serializing a RR of type PTR, we should use the DNS name serialization
format, not a raw string.
2021-02-15 09:14:42 +01:00
Sergey Bugaev
d6f7ced4f1 LookupServer: Move DNS name serialization to DNSName class 2021-02-15 09:14:42 +01:00
Sergey Bugaev
42bc5f2cc1 LookupServer: Move parse_dns_name() -> DNSName::parse()
While at it, refactor it slightly.
2021-02-15 09:14:42 +01:00
Sergey Bugaev
ae1e82fd2f LookupServer: Introduce DNSName
This is a wrapper around a string representing a domain name (such as
"example.com"). It never has a trailing dot.

For now, this class doesn't do much except wrap the raw string. Subsequent
commits will add or move more functionality to it.
2021-02-15 09:14:42 +01:00
Stephan Unverwerth
de811faf55 LibTTF: Address some minor TODOs in the font implementation 2021-02-15 08:50:48 +01:00
Stephan Unverwerth
05d31cbeeb LibTTF: Add hack for recognizing fixed-width fonts 2021-02-15 08:50:48 +01:00
Stephan Unverwerth
53d2073a66 Resources: Add SerenitySans Truetype font to /res/fonts 2021-02-15 08:50:48 +01:00
Stephan Unverwerth
3b67b55c84 LibGfx: draw_glyph_or_emoji fix check for available glyph
This would cause question marks to be rendered when a ttf with fewer
glyphs than the value of the code_point was used.
2021-02-15 08:50:48 +01:00
Stephan Unverwerth
6948f9ca55 TextEditor: Allow picking non-proportional font 2021-02-15 08:50:48 +01:00
Stephan Unverwerth
b8c25bc7ff LibGfx: Remove static load_from_file() from abstract Font class 2021-02-15 08:50:48 +01:00
Stephan Unverwerth
79dfe9846d LibGfx: Generalize glyph placement in Painter 2021-02-15 08:50:48 +01:00
Stephan Unverwerth
972c7cf9f4 LibGUI: Add some default sizes for TTF fonts in FontPicker 2021-02-15 08:50:48 +01:00
Stephan Unverwerth
85158dc0ad LibGfx+LibTTF: Allow Painter to draw TTF glyphs 2021-02-15 08:50:48 +01:00
Stephan Unverwerth
0f41f5d9ba LibGUI+LibGfx+LibTTF: Make fontpicker handle TTF fonts 2021-02-15 08:50:48 +01:00
Stephan Unverwerth
5a70ccecb3 LibGfx: Add more query methods to FontDatabase and Typeface 2021-02-15 08:50:48 +01:00
Stephan Unverwerth
e504d4ef96 LibGfx: Add Color::multiply() for component wise multiplication 2021-02-15 08:50:48 +01:00
Stephan Unverwerth
179dba652e LibGfx: Insert pixel and ttf fonts into Typeface structure
This adds a new structure 'Typeface' to the FontDatabase that
represents all fonts of the same family and variant.
It can contain a list of BitmapFonts with varying size but of
the same family and weight or a pointer to a single TTF font
for all sizes of this Typeface.
2021-02-15 08:50:48 +01:00
Stephan Unverwerth
2c4e13f14a LibTTF: Parse TTF "name" table 2021-02-15 08:50:48 +01:00
Brian Gianforcaro
f12754ee10 Kernel: Mark BlockResult as [[nodiscard]]
In the majority of cases we want to force callers to observe the
result of a blocking operation as it's not grantee to succeed as
they expect. Mark BlockResult as [[nodiscard]] to force any callers
to observe the result of the blocking operation.
2021-02-15 08:28:57 +01:00
Brian Gianforcaro
a8a834782c Kernel: Ignore unobserved BlockResult from Thread::Sleep
Suppress these in preparation for making BlockResult [[nodiscard]].
2021-02-15 08:28:57 +01:00
Brian Gianforcaro
ddd79fe2cf Kernel: Add WaitQueue::wait_forever and it use it for all infinite waits.
In preparation for marking BlockingResult [[nodiscard]], there are a few
places that perform infinite waits, which we never observe the result of
the wait. Instead of suppressing them, add an alternate function which
returns void when performing and infinite wait.
2021-02-15 08:28:57 +01:00
Andreas Kling
4ac286903d Meta: Add Ports/build_installed.sh to the lint-ports ignore list 2021-02-15 07:51:40 +01:00
Ben Wiederhake
ad4d9eaaf9 Meta: Lint AvailablePorts.md
As requested by popular demand ;)
https://github.com/SerenityOS/serenity/pull/5325#discussion_r575657614
2021-02-15 07:41:16 +01:00
Ben Wiederhake
87e4bcdf69 Everywhere: Canonicalize 'ReadMe' capitalization
We now follow a common capitalization throughout the project:

./Ports/openssh/ReadMe.md
./Ports/python3/patches/ReadMe.md
./Ports/ReadMe.md
./Meta/Lagom/ReadMe.md
./ReadMe.md

This filename is still obvious enough to be seen immediately.
2021-02-15 07:41:16 +01:00
Andreas Kling
68e3616971 Kernel: Forked children should inherit the signal trampoline address
Fixes #5347.
2021-02-14 18:38:46 +01:00
Andreas Kling
8ee42e47df Kernel: Mark a handful of things in CPU.cpp as READONLY_AFTER_INIT 2021-02-14 18:12:00 +01:00