|
|
Log in / Subscribe / Register

LWN.net Weekly Edition for April 18, 2019

Welcome to the LWN.net Weekly Edition for April 18, 2019

This edition contains the following feature content:

This week's edition also includes these inner pages:

  • Brief items: Brief news items from throughout the community.
  • Announcements: Newsletters, conferences, security updates, patches, and more.

Please enjoy this week's edition, and, as always, thank you for supporting LWN.net.

Comments (none posted)

An update on compliance for containers

By Jake Edge
April 16, 2019

LLW

The inability to determine the contents of container images is a topic that annoys Dirk Hohndel. At last year's Legal and Licensing Workshop (LLW), he gave a presentation that highlighted the problem and some work he had been doing to combat it. At this year's LLW, he updated attendees on the progress that has been made and where he hopes things will go from here.

Hohndel is the chief open source officer at VMware, but his talk has little to do with his company. The topic comes out of his sense of annoyance with the problem; when he gets annoyed, he tends to do something about it, which sums up much of his career, he said. He has given his containers and compliance talk to both compliance and security people, because the problem is basically the same for both. When you ship a container image, what is actually in it and where does that code come from? That is obviously a license-compliance problem, but it is also a security concern; distributors of these images should want to know what is in them and recipients should want to as well.

[Dirk Hohndel]

When he gives his talk, the responses follow a pattern; first there is a "little embarrassed laughter", then surprise, and, finally, attendees start looking around for someone else to do something about it. He took an informal audience poll to see how many had actually created a compliance process specifically for container images. Usually he gets no hands raised, but he got a few tentative ones at LLW, which he said was the first time that had happened. Everyone is talking about containers, of course, and Kubernetes is apparently the most important technology project of this millennium, he said, but he is "deeply surprised" that the topic does not come up more often in our community.

Container images are really nothing particularly new; they are just a packaging format for software. As with Linux distribution packaging formats or those for macOS or Windows, it is matter of ensuring that all of the dependencies for the software of interest are packaged or available with it. What container systems have done is to make it all easy; they have changed the art of packaging software from an engineering thing to a point-and-click exercise. That greatly reduces the barriers to entry, but the "best practices"—he explicitly pointed out that he was using "air quotes" for that term—available online are terrible. In last year's talk, he gave examples of some of what ends up in these images by following those practices, he said.

Progress

So, Hohndel asked, one year later, "have we made any progress at all?" There is a new Linux Foundation (LF) project, Automated Compliance Tooling (ACT), that has two sponsors, one of which is his employer. The focus of the project is to jointly develop tools to help address these problems. The name "ACT" has "so much irony" that he is unable to even come up with a joke about it, he said.

The fact that it is an LF project gives ACT both visibility and credibility, which is great, but there are few organizations that are working on it, which is frustrating. He highlighted three projects that are part of ACT: Tern, which he talked about a bit last year, Quartermaster (or QMSTR), and FOSSology. He spoke with various other people about them at the recently held Open Source Leadership Summit, which is misnamed, he said, since it is really the annual LF membership meeting. For the first time, though, he got traction with other open-source projects in the compliance space; there were discussions of how to integrate the tools in various ways to make them more useful for everyone.

The container-management tooling that creates container images uses layers to build up the image. The layers are essentially tar files with some extra pieces to describe how they fit and they are designed to replace pieces from the lower layers—without users being aware that it is being done. From a usability perspective, "that is fantastic", he said, but for compliance and security, "not so much". People were interested and curious about the container-compliance problem, but no one seems to think it is an urgent problem that they need to immediately solve.

Trolling

Lawyers are risk averse, he said, whereas engineers will happily take risks, especially when they don't understand them—compliance and security fall into that category in his view. The lawyers in the community don't care about these problems because there has not been any enforcement action against container images. And the engineers say that the problem does not matter because the technology works. In order to combat that, what is needed is an enforcement threat, he said.

He suggested creating a "troll company" to start doing some enforcement activity. The "Trolltech" name suggestion from the audience was met with laughter, but shot down since it had already been used. Hohndel said that he was "kind of joking", but that "the line between a bad joke and the true reality is very very thin". He does not own any substantial copyright in the components of today's container images so he cannot simply do this on his own—sadly, no one is making Subsurface container images.

But it would be fairly easy for someone with bad intentions to go after container distributors for not complying with the licenses in their containers. For example, BusyBox and libraries under the GPLv3 with the runtime exception are in most containers. Enforcement of that sort might lead everyone to start using only permissively licensed code, which is not what we want, he said.

Tooling is the answer, he said. It can create an artifact that goes with the image, which contains all of the copyright notices as well as providing information on where to find the correct and corresponding source code for components that need it. That is what Tern is meant to do. It will dig into a container image, tear it apart, and provide an accurate assessment of what is inside it. For images based on APT and RPM components, Tern will create a bill of materials (BOM) that contains all of the different copyright notices, license information, including Software Package Data Exchange (SPDX) headers once that part gets upstream, and pointers to the source files. But it is also an open-source project that needs a lot more help. Unfortunately, "no one cares", he said.

Needs

Hohndel closed his talk with two requests for the assembled lawyers, engineers, and others interested in licensing issues who make up the attendees at LLW. First is help with the engineering projects. It is not necessary to be an LF member to contribute; these are normal open-source projects that are looking for help.

Second, he would like to get attendees' help in spreading the word about these problems. It can't only be him that is going around to conferences and talking about it. He would like to make it a topic of conversation in our community, but he would also like to get various big players in the container world to listen—and help. For example, getting Docker to take the problem seriously and for the Cloud Native Computing Foundation (CNCF), which is shepherding the Kubernetes project among others, to require that the base container images used in its projects have compliance information available.

With that, he switched to Q&A. One attendee asked about creating compliance artifacts as part of the build process, rather than after the fact. Container images should be compliant at the point they are pushed to image repositories, they said. Tern can do both, Hohndel said; it can build up its information during the creation of the image or later. It is significantly harder to do that after the fact, however.

Karen Sandler of the Software Freedom Conservancy (SFC) said that her organization does care about this problem. She recommended that people report non-compliant images to SFC. There is no need to be a rights-holder in the code involved to make a report, she said.

Another attendee said that the information should somehow be made part of the container image or, at least, accompany the image. This is one of the things that really irritates him, Hohndel said. Information about licenses was proposed for Dockerfiles at one point, but it was removed. He has been thinking that the universal identifiers created by Software Heritage would be a great way to link to the source code, but there is no way to get those into the binary image file. He believes that sidecar files are not a viable solution for end users, because those files have a tendency to get lost along the way. He also noted that there are some container-tools vendors that are touting the ability to strip "extra" information (e.g. package information) from images in order to reduce their size.

Container people are interested in scanning images for security vulnerabilities, another attendee said. They wondered if it might make sense to team up with a project like Clair. Hohndel said that container folks are interested in the BOM, but not the copyright and source code information. Tern is modular, though, so it is easy to add scanning target types; once it was able to do some of the scanning, some of the security projects started talking with Tern developers.

Engaging the major cloud players in helping to enforce compliance on the images that their customers run was another question. Hohndel said that he has talked with people from some of the cloud providers (e.g. Amazon and Google) to try to enlist their aid, but there was little enthusiasm there. When you are in the business of selling compute resources to customers, it is not in your financial interest to make that harder, he said.

The final query was about Alpine Linux, which is used as the base distribution for many container images. The attendee noted that Alpine strips all of the license files from its layer. Hohndel said that it is worse than that, in that Alpine strips all information about versions, except those actually stored in the individual binaries, from its layers. It makes it essentially impossible to comply with the licenses of the packages that it uses (e.g. BusyBox). Another attendee said that they have some contacts at Alpine and suggested that might be a path toward resolving the problem. Hohndel closed by saying that making that contact meant that his presentation was a complete success for him.

[I would like to thank the FSFE and the LLW Diamond sponsors, Intel, the Linux Foundation, and Red Hat, for their travel assistance to Barcelona for the conference.]

Comments (18 posted)

Business models and open source

By Jake Edge
April 17, 2019

LLW

One of the more lively sessions that was held at the 2019 Legal and Licensing Workshop (LLW) was Heather Meeker's talk on open-source business models and alternative licensing. As a lawyer in private practice, Meeker worked on a number of the alternative licenses that were drafted and presented over the last year or so. But she is also part of a venture capital (VC) firm that is exclusively investing in companies focused on open source, so she has experience in thinking about what kinds of models actually work for those types of businesses.

The LLW is organized annually by the Free Software Foundation Europe (FSFE). It is meant as a gathering for lawyers, engineers, and others interested in licensing topics. By default, sessions are run under the Chatham House Rule, which means that participants cannot be identified, either by name or affiliation. Meeker waived that rule for her talk, though those from the audience who made comments may or may not have waived the rule.

Meeker acknowledged that her topic was controversial, but that she would be "your Beatrice [from the Divine Comedy] to the miasma of venture-backed open-source companies". Her slides were entitled "What color are your razor blades? FOSS business models". The title is referencing the famous What Color is Your Parachute? book for job seekers. The idea is to imagine an idea with specificity, so open-source companies need to imagine what they are selling (their "razor blades") with specificity in order to be successful.

Otherwise, she said, they end up with the business model of the Underpants Gnomes ("1. Collect underpants, 2. ?, 3. Profit"). For a long time, there was a tendency for open-source entrepreneurs to equate "lots of downloads" with profit, which is more or less the same thing. That is not really going to happen unless a lot of thought is put into how the business will actually function.

Business and open source

Meeker was glad to hear other presentations at LLW make the distinction between open source as a licensing model and as a development model. It is something that she and others have been trying to get across to people who are trying to understand what open source is. She took that one step further to say that open source is not a business model. There are, however, business models that employ open source as an important strategy. Though some will disagree with her, she thinks it is beside the point to ask if a business is an "open-source business" because for-profit businesses may use open source as part of their strategy, but that doesn't make them an open-source business.

[Heather Meeker]

She noted that she had not invented any of the business models she was presenting, she has simply collected her thoughts on what she has observed. For "open source", she is referring to the "Cathedral and Bazaar" style of community development, where the code is generally available under an open-source license. Open source has become "big business" these days; people have begun to recognize its incredible power for building businesses, she said.

She likes to joke that since she is a lawyer in Silicon Valley, none of her clients (generally startups) make any money. After years of people asking her how money can be made with open source, business models that strategically use open source have proven that they can create lots of products and, ultimately, generate lots of profit. The traditional VCs are saying that they need to understand open source better, which is a big change in the landscape.

In the last year, she has joined OSS Capital, which is a VC fund for early-stage companies that use open source as an important strategy. She showed the Commercial Open Source Software Company Index (described here) that was created by her OSS Capital partner, Joseph Jacks, to track businesses using open source with more than $100-million in annual revenue.

From that, she extracted six companies that had been acquired or done an IPO in mid-late 2018, which was a watershed year for the emergence of open source into the minds of VCs and others. The numbers were "an astonishing result", she said, with the Red Hat acquisition at $34 billion dominating, though Mulesoft and GitHub were also subject to multi-billion-dollar acquisitions. These and others were eye-opening exit events that made the VC community take notice.

Business models

First off, Meeker wanted to make it clear that she is talking about companies that develop open-source software and not companies that are "hoovering up" open-source software to use in their products and services. The razor blades idea comes from the "give away the razor and sell the blades" business model. Any business that is using open source as a strategy needs to figure out what its blades are, she said, since the software itself is the free razor.

There is the "pure open-source" model, where the blades are maintenance and support. It is common, especially among smaller companies, but also for Red Hat, which is the largest. The idea is to sell services and not software rights; it is the most straightforward model, but also the one that causes people to ask her how money can be made with open source.

In reality, what those companies are selling is quality. Customers could get maintenance and support from anyone, but they choose to get it from a particular vendor because they believe they will will get a certain level of quality. The IT procurement people who choose these vendors are not buying the availability of the source code; they are buying services from a company they trust.

"Online services" is another model. Her examples for that model are GitHub and WordPress. The software may be open source, but some people don't want to run it themselves. She has a WordPress site, but she pays to have it run on the WordPress servers because she doesn't want to set it up and maintain it for herself. These companies are selling convenience. The big online cloud-services companies are also using this model, but it is much more complex.

The "professional services" model was one used by MontaVista Software, which was a former client of hers. The company would customize open-source software and provide professional services to its clients in the embedded market. If a company wanted Linux to run on a particular device, MontaVista would build and maintain it under a contract for services.

So those three are all services of one kind or another: support, online, or professional. In her "lawyer mind" they all fall under service contracts, rather than software licenses. Those were the fairly straightforward and non-controversial models; next up were more complex and controversial ways of doing business using open-source software.

Controversial models

The first of these was the "dual-licensing" model, which was pioneered by MySQL. The intent was to provide customers a way to buy their way out of having the GPL apply to their code. It started out as the "identical twin" model, where the software was exactly the same under both licenses. That started to evolve into the "fraternal twin" model, where the open-source version was somewhat different than the commercial edition. In the early 2000s, there were lots of investments in those types of companies, she said.

The fraternal twin model evolved into the "open core" model as the "twins" got further and further apart. Open core is probably the most popular model in the VC community, she said. Normally, the core of the software is released under an open-source license, with extra bells and whistles sold under commercial software licenses. Typically, the extras are needed to deploy the software at scale; the "whole kit and kaboodle" was sold in a package, often as an "enterprise edition".

An alternative turns that on its head. In that case, the core is proprietary, while the add-ons are open source. She does not know of any "non-stealth examples", though one could look at the iPhone model as being somewhat similar—the core is proprietary and the apps can be open source. In both cases, maintenance and support are normally bundled with the proprietary piece(s). One question is whether customers continue to get the open-source piece under an open-source license, thus without any warranties, or whether the entire code base is conveyed under the proprietary license; that varies between companies that offer these models.

"Widget frosting" is a model where a company is selling a hardware device and releases an open-source toolkit or SDK that allows others to add functionality for the device. Here, the razor is the software and the blades are the devices themselves.

The final model she presented was the "embargo" model. It is moderately common in certain industries. The idea is that beta releases of the software are made available to paying customers ahead of a full open-source release to everyone. In fast-moving markets, some will pay for the ability to get a first look that will put them ahead of the curve.

"Which of these models work from a business point of view?" Her partner at OSS Capital would say that open core works the best. Of the roughly 40 companies in the index that he maintains, 25 are open core and eight are software as a service (SaaS) and open core hybrids.

Changes

There was a trend in the latter half of 2018 where companies were resetting their business models. She worked with several companies, such as Redis, Confluent, Elastic, and Chef, as well as on the Commons Clause exception for permissive licenses. These companies (and clause) have changed the line between what is open core and what is not. For the most part, they limited what was in their core and expanded the proprietary pieces.

First off, "the demand to do this was incredible", she said. The VCs were clamoring for ways to make this change while still keeping things as open as possible under the company's business model. They typically just readjusted the line. The reason these moves got so much coverage in the open-source world is that pieces that were formerly released as open source got moved into the proprietary bucket; those were the changes that brought the attention.

The companies that made these changes were typically in the "middleware" market space, she said. That is they were not "pure infrastructure", such as a kernel, and they were not applications. What they made is "extremely valuable" to the cloud-service providers that were all using (and selling) these tools. Some of the companies developing the code began to take issue with the cloud providers' use, so they created alternative licenses that were meant to try to capture more of that value for themselves.

Meeker said that she did not go into more detail here because she expected the Q&A section to cover a lot of that.

Finishing up

She ended the talk part of her presentation with something of a grab bag of her thoughts on investing in open source. She has a blog post at OSS Capital that describes why companies using open source as part of their strategy make good counter-cyclical bets for investing. The market is cyclical, and those who will do well know how to make money in both up and down markets.

The blog post shows an analysis of companies that developed open source with regard to when they were started. She said that it overwhelmingly shows that companies started developing open source during a downturn "represent probably one of the best leveraged capital investments you can possibly make". They make "very efficient use of resources" and by the time they are ready to release, the economy has generally gone into an upswing. That blog post (and the underlying analysis) may be of interest to some, she thought.

Another observation is on why there are not more companies following the pure open-source model. In order for that model to work, it needs to be based on a big project, such as basic infrastructure. The idea is that there are lots of potential customers, so the volume of sales can make up for thinner margins. That is easier to do when there is a large user base, but it is still not easy to pull off.

She concluded by pointing to her book, Open (Source) for Business: A Practical Guide to Open Source Software Licensing, which is now in its second edition and available from her web site. She noted that she hands out paper copies "like candy" and that a free e-book version is available for those who sign up for her newsletter.

Q&A

As predicted, many of the questions were about the changes being made by companies that develop (some) open source. One attendee said that hearing the term "commercial open-source software" made them cringe as "commercial" is incongruent and potentially confusing when coupled with "open source". They had tried to come up with another term, but could only really do that with a full sentence. They wondered what Meeker's thoughts were on that.

When she talks to business people and developers, "they don't care what we mean by 'open source'", Meeker said. She is sorry that is the case, but there is an "enormous divide" between the definitions used by many attendees and those held by lots of developers, especially those who are running businesses. There is not enough communication between the groups, which is problematic.

Meeker said that perhaps the "commercial open source" term is not a good one, but that there is a lack of terminology to use. It is generally not meant to refer to anything but the business model and is not about the licensing model. To many successful entrepreneurs, there is no inconsistency in using that term; they are not trying to challenge the open source definition, she said.

Another attendee said that part of the concern is that there is a level of deception by using "open source" to mean something different than its definition. The term "openwashing" is sometimes used in this context to describe companies that are trying to ride the coat tails of the open-source movement without really being open.

If the licenses, FAQs, and such that have come out about these changes are misleading, Meeker said, then that is a problem. But she thinks the companies have been quite clear and, for her part, she did her best to help her clients ensure that that they were not trying to confuse anyone. Clients do not always follow the advice they are given, though.

She suggested not shooting her as the messenger, however. The business people have their own notions of what these terms mean. There are only a certain number of words that can be used; all of the possibilities for "open", "free", "community", "commons", and so on cannot be completely controlled by existing definitions. She spent a lot of time consulting thesauruses to try to find other terms for "open" and "free"; there is no word for what these companies are trying to do and every time they try to use one, they get shot down. From what she has heard, though, people are complaining about things that are not in the licenses or FAQs, so she would like to see people actually read the source material before they make (and voice) a judgment.

There cannot be clarity of thought without clarity of language, however, another attendee said; "open source means open source", they said to applause. There are decades of "blood, sweat, toil, and tears" invested in open source as it is meant in the room; "it is thievery" to coopt the definition. They suggested calling it something else: "call it macaroni for all I care".

She has tried to be careful in her presentation and elsewhere to talk about businesses using open source as part of their strategy, Meeker said. She does not counsel clients to use the term incorrectly. If asked, she would tell them to say that their product is fantastic and that some of it is available under an open-source license.

"I suggest that it is only an open-source business model if the customer ends up with software freedom", another attendee said, again to applause. People came to the open-source movement because they were after personal freedom of various sorts. The term "open core" was actually coined as a positive term for the kinds of businesses she is describing, but it is not used because people say it does not have marketing value for their businesses. Meeker did not agree about "open core" as she believes it is a pretty commonly used term.

The open-source ecosystem has moved on; it has evolved, another attendee said. There are a lot of licenses out there that are not approved by the Open Source Initiative (OSI); most people believe that Debian is made up of open-source software, but it has software under lots of different licenses that are not OSI approved. In addition, their view is that the interpretation of the OSI definition of open source has evolved over time, which reduces their confidence in it as the guide for what open source is. LLW attendees can debate what open source is all they want, but the reality is that it is a superset of the licenses that have been approved.

As a personal note, Meeker said, she thinks it is a big tent and not a small tent. We should make room for people trying different things; she does not believe it is wrong to have private companies developing open-source software or that it is inconsistent with what is meant by "open source". Lawyers do their work in service to their clients, however; the clients will sometimes do things whether the lawyers approve of it or not.

Another attendee wondered if OSS Capital had considered doing a survey to try to determine what "open source" means in the wider world. They think that it might show that the definition is not as clear cut as the "open source means open source" applause line might indicate. Meeker agreed that it might be something worth trying. What she hears from her clients, who are largely developers and business people, not lawyers, is that they have a different idea about what the term means. "You can't shout them down by us all agreeing; that's not going to change their behavior."

Shifting gears a bit, another attendee asked about the statement that open-source business models do better in a downturn because they use capital more efficiently. Meeker said that during a downturn, entrepreneurs are more likely to start working on an open-source project, perhaps as a way to show potential employers their credentials—it has value on a resume, for example. That situation is more likely to occur in downturns, when people are out of work.

When those projects are being developed, the people behind it are not renting offices or buying lunch for their employees, so a small investment can go a long way. You could invest $500K in such a project, which might fund a whole lot of development, while a proprietary company would burn through that investment in short order. There is also a lot of value coming from the community because it can look at the code and will provide more feedback than is possible for a proprietary company.

It is clear that there are different, strongly held opinions—in the room and outside it. There were a few other questions and comments along the way, but it is not a subject that is amenable to resolution anytime soon or, perhaps, ever. Though there was talk of "unfair competition" in using "open source" in a deliberately, or simply mistakenly, confusing way, it is hard to imagine this being resolved by any court other than the court of public opinion. And, at this point, the ship may well have sailed on a restrictive interpretation of the term.

[I would like to thank the FSFE and the LLW Diamond sponsors, Intel, the Linux Foundation, and Red Hat, for their travel assistance to Barcelona for the conference.]

Comments (8 posted)

Expedited memory reclaim from killed processes

By Jonathan Corbet
April 12, 2019
Running out of memory puts a Linux system into a difficult situation; in the worst cases, there is often no way out other than killing one or more processes to reclaim their memory. This killing may be done by the kernel itself or, on systems like Android, by a user-space out-of-memory (OOM) killer process. Killing a process is almost certain to make somebody unhappy; the kernel should at least try to use that process's memory expeditiously so that, with luck, no other processes must die. That does not always happen, though, in current kernels. This patch set from Suren Baghdasaryan aims to improve the situation, but the solution that results in the end may take a different form.

The kernel requires processes to clean up their own messes when they exit. So, before a process targeted by an OOM killer can rest in peace, it must first run (in the kernel) to free its memory resources and return them to the system. If the process is running with a low priority, or if it gets hung up waiting for a resource elsewhere in the system, this cleanup work may take a long time. Meanwhile, the system is still struggling, since the hoped-for influx of free memory has not yet happened; at some point, another process will also be killed in the hope of getting better results.

This problem led to the development of the OOM reaper in 2015. When the kernel's OOM killer targets a process, the OOM reaper will attempt to quickly strip that process of memory that the process will never attempt to access again. But the OOM reaper is not available to user-space OOM killers, which can only send a SIGKILL signal and hope that the target exits quickly. The user-space killer never really knows how long it will take for a killed process to exit; as Baghdasaryan pointed out, that means that it must maintain a larger reserve of free pages and kill processes sooner than might be optimal.

Baghdasaryan's proposal is to add a new flag (SS_EXPEDITE) to the (new in 5.1) pidfd_send_signal() system call. If that flag is present, the caller has the CAP_SYS_NICE capability, and the signal is SIGKILL, then the OOM reaper will be unleashed on the killed process. That should result in quicker and more predictable freeing of the target's memory, regardless of anything that might slow down the target itself.

The comments on the proposal were heavily negative, which is interesting because most of the people involved were supportive of the objective itself. The strongest critic, perhaps, was Michal Hocko (the author of the OOM reaper), who complained that it "is abusing an implementation detail of the OOM implementation and makes it an official API". He questioned whether this capability was useful at all, saying that relying on cleanup speed is "a fundamental design problem". Johannes Weiner, though, argued that the idea was, instead, "just optimizing the user experience as best as it can". Others generally agreed that freeing memory quickly when a process is on its way out is a good thing.

Daniel Colascione liked the idea but wanted a different interface. Rather than adding semantics to a specific signal, he suggested a new system call along the lines of:

    size_t try_reap_dying_process(int pidfd, int flags, size_t max_bytes);

This call would attempt to strip memory from the process indicated by pidfd, but only if the process is currently dying. The max_bytes parameter would tell the kernel how much memory the caller would liked to see freed; that would allow the kernel to avoid doing the full work of stripping the target process if max_bytes has been reached. Notably, the reaping would be done in the context of the calling process, allowing user space to determine how important this work is relative to other tasks.

Matthew Wilcox had a simpler question: why not just expedite the reclaim of memory every time a process exits, rather than on specific request? Weiner agreed with that idea, noting that the work has to be done anyway, and doing it always would avoid the need to add a new interface for that purpose. Daniel Colascione pointed out, though, that such a mechanism would slow down the delivery of SIGKILL in general; that slowdown might be felt when running something like killall.

Baghdasaryan didn't think that expedited reaping makes sense all the time. But, he said, there are times when it is critical. "It would be great if we can identify urgent cases without userspace hints, so I'm open to suggestions that do not involve additional flags". If such a solution can be found, it is likely to end up as the preferred alternative here. Cleaning up after a killed process is, in the end, the kernel's responsibility, and there is little desire to create a new interface to control how that responsibility is carried out. Solutions that "just work" are thus to be preferred over the addition of yet another Linux-specific API for this purpose.

Comments (25 posted)

Avoiding page reference-count overflows

By Jonathan Corbet
April 16, 2019
The 5.1-rc5 announcement mentioned "changes all over" and highlighted a number of the areas that had been touched. One thing that was not mentioned there was the addition of four patches fixing a security-related issue in the core memory-management subsystem. The vulnerability is sufficiently difficult to exploit that almost nobody should feel the need to rush out a kernel update, but it is still interesting to look at as a demonstration of how things can go wrong.

One of the many things crammed into struct page is a field called _refcount; it is an atomic_t variable that counts the number of references to the page in question. As an atomic_t, it's a signed, 32-bit quantity. As long as this count is nonzero, references to the page exist and it cannot be reused for other purposes; once it drops to zero, the page can be freed.

As with any counter in the kernel, _refcount should be manipulated with care lest it overflow. If one looks at the definition of get_page(), one will see this check:

    VM_BUG_ON_PAGE(page_ref_count(page) <= 0, page);

If the reference count is incremented beyond the maximum positive value that can be held in a 32-bit signed variable (2,147,483,647), it will wrap around to the largest-magnitude negative value (-2,147,483,648). That, of course, wanders into undefined behavior, so the compiler is entitled to set it to 0xdeadbeef and erase the disk drives instead if it so chooses. With reasonable compilers and a two's complement representation, though, one can expect the count to go negative when it overflows; that is what the above test is checking for.

There are a couple of interesting things to note about this test. One is that it happens before _refcount is incremented, so it will only trigger on the second overflow. That is not a problem, though, since the system will behave as expected — even with negative reference counts — as long as the count is not incremented all the way back to zero. The other thing to note is that, while VM_BUG_ON_PAGE() will crash the kernel when the CONFIG_DEBUG_VM configuration option is selected, it does precisely nothing in production builds. So, on most systems, an overflow of the page reference count will go undetected. That is potentially bad: if the reference count can be incremented to the point where it returns to zero, the page will be freed while a vast number of references remain, and a variety of use-after-free vulnerabilities will result. Good things do not generally ensue after an event like that.

That said, memory-management developers have had good reason to be unworried about this eventuality. Overflowing the reference count to zero would require creating a full four-billion references to the page in question (the negative reference counts for the second two-billion references would look weird, but things will work as intended), and that is not an easy thing to do. As it turns out, according to this merge commit, Jann Horn has figured out how to do it, and it was indeed not easy:

To have more than four billion references to a page requires a minimum of 32GB of kernel memory just for the pointers to the pages, much less any metadata to keep track of those pointers. Jann needed a total of 140GB of memory and a specially crafted filesystem that leaves all reads pending (in order to not ever free the page references and just keep adding more).

Most of us are unlikely to give such resources to an attacker, even when asked nicely. But a bug is a bug, and the developers who were privy to the information about Horn's exploit decided to fix it. The result was four commits (from Linus Torvalds and Matthew Wilcox) making this particular hole even harder to exploit.

The "specially crafted filesystem" mentioned above is necessary because it is not easy for an attacker running in user space to create large numbers of references to a given page. Simply creating a lot of mappings using mmap() or fork() would run into other limits long before the reference count overflowed. One way that does seem to work, though, is to create large numbers of direct-I/O requests, each of which acquires a reference while the operation is underway. Should the filesystem be extremely slow to finish those operations — even slower than VFAT — the references could eventually add up to the magic number.

The first step toward preventing such exploits was to create a macro to check whether a given reference count is getting close to going negative:

    #define page_ref_zero_or_close_to_overflow(page) \
	    ((unsigned int) page_ref_count(page) + 127u <= 127u)

The VM_BUG_ON_PAGE() check shown above was then changed to use this macro. On systems where VM_BUG_ON_PAGE() does anything at all, this new test should prevent reference counts from going negative, thus stopping things far short of incrementing all the way to zero.

That said, if CONFIG_DEBUG_VM is set on a target system, an attacker could still use this overflow for denial-of-service attacks. To prevent that, Torvalds created a new try_get_page() function that will refuse to acquire a reference if the count is close to overflowing. Then, get_user_pages() was changed to use try_get_page() and to fail the entire operation if the needed references cannot be acquired. With those changes in place, direct-I/O requests that threaten to overflow a reference count will simply fail, and the attacker will be left looking for other good uses for 140GB of free memory. Another possible exploit, using pipes, was closed off in a similar fashion by Wilcox.

While these changes were added late in the release cycle like an urgent fix, this clearly isn't a vulnerability that has a lot of people worried. In fact, it was first discussed in January on the closed kernel security list, but then the developers involved simply forgot about it for a while. That lapse has now been rectified, which is a good thing; one never knows when somebody might discover an easier way to force the page reference count to overflow. When that happens, the patches merged for 5.1-rc5 should be able to prevent a severe compromise of the system.

Comments (19 posted)

Counting corporate beans

By Jonathan Corbet
April 12, 2019

Free accounting systems
Some things simply take time. When your editor restarted the search for a free accounting system, he had truly hoped to be done by now. But life gets busy, and accounting systems are remarkably prone to falling off the list of things one wants to deal with in any given day. On the other hand, accounting can return to that list quickly whenever LWN's proprietary accounting software does something particularly obnoxious. This turns out to be one of those times, so your editor set out to determine whether beancount could do the job.

Beancount was already covered here almost exactly one year ago, but that review was focused on personal finances; company accounting has a different set of requirements. That article is worth reviewing, though, as the material covered there will (mostly) not be repeated here. Here, instead, the emphasis will be on what a simple business needs.

At the top of the list is the ability to import data into the system and to get it back out again. An ongoing business has a long accounting history that needs to be present going forward. Beancount keeps all of its data in a plain-text file with a well-documented format, so both import and export are relatively easy. Building on the the tools written to extract data from QuickBooks, your editor was able to write a script to import the accounting database into beancount over the course of an hour or two.

File formats

There are a couple of things worth noting about the format of the beancount file, though. A typical transaction entry looks like this:

    2019-04-01 txn "Faithful reader" "Subscription, professional hacker, 12 months"
      Assets:Paypal              71.97 USD 
      Income:SubscriptionIncome -75.60 USD 
      Expenses:PayPalExpense      3.63 USD 

The first line provides the date and overall descriptive information; the following lines describe the various components of the transactions. These lines are called "postings" in beancount; many other systems will call them "splits" instead. By whatever name, they describe the movement of funds from one account to another; the amounts in the postings must add up to zero. This format has all of the basic information, but there are some shortcomings too.

For example, there is no way in the base format to note whether a transaction has been reconciled or not. Reconciliation is a crucial feature in an accounting system; it's how you know that your view of a specific account matches that of the financial institution on the other side. Beancount provides the ability to "assert" the balance in an account on any given date; it will then verify that the assertion is true. But that falls apart when there is a time lag between when a transaction is initiated and when it shows up in the account; outstanding checks are one example, but there are many others. Lack of proper reconciliation is a nearly fatal flaw in its own right for this particular use case.

One could of course add this feature. Beancount provides the ability to attach "metadata" to transactions, so one can add a flag that looks like this:

    2019-04-01 txn "Faithful reader" "Subscription, professional hacker, 12 months"
      reconciled: "no"
      Assets:Paypal              71.97 USD 
      Income:SubscriptionIncome -75.60 USD 
      Expenses:PayPalExpense      3.63 USD 

Then one could write the tools to support the reconciliation pass. Other missing data, such as check or transaction numbers, could be supported in the same way. It would all work, but the whole purpose was to not have to actually write the accounting system.

There's another interesting question here: how does beancount distinguish the metadata line above from the splits? It turns out that it's all done with case: account names must start with a capital letter, while metadata "keys" must be entirely lower case. Currencies ("USD" above) must be all upper case. Rules of this nature strike your editor as being somewhat fragile and unobvious; they could also restrict the project's ability to extend the transaction format in the future.

It is also worth noting that beancount explicitly ignores any lines in the file that it doesn't recognize. The apparent purpose of this feature is to allow other types of markup in the file; the ability to manage it with the Emacs Org mode is said to be especially gratifying. But this behavior can also make it easy for mistakes to pass unnoticed. Similar behavior in cron has led to security vulnerabilities in the past. Your editor would feel much better knowing that a corrupted beancount file would not escape notice.

Doing accounting

Since beancount is primarily a command-line application, there are no fancy user interfaces for dealing with accounting data. There is an Emacs mode that can help with the creation of transactions; it can perform helpful tasks like name completion. Much of the rest is expected to be done with scripts; there are a number of tools for importing transactions from various sources and a plugin mechanism to augment the processing of those transactions.

Many of the features that one would expect from an accounting system are absent from beancount. There is no ability to generate and track invoices, for example. The same can be said for bills. Indeed, beancount doesn't really have a concept of "accounts receivable" and "accounts payable" built into it. Again, one could add that with a bit of work, but that would be more work to do.

Another significant missing feature is the ability to detect and merge duplicate transactions. The failure to store transaction numbers makes things worse here. The beancount documentation talks about how, with balance assertions in place, duplicates will generate errors that can then be fixed up by hand. That may be tolerable in a personal-finance system; it will lead to significant grumpiness in a business accounting system that has to handle far more transactions.

There is a rudimentary set of reports built into beancount; they look the way one expects a balance sheet or a profit-and-loss statement to look, but there is a lack of flexibility. For example, it is pretty normal to want to restrict a report to a given period of time. The command-line tools appear to lack that capability entirely; the bean-web and fava web-based tools can only select a full year at a time. Fava can generate a basic line plot, but otherwise there is no ability to create plots at all. No pie charts for beancount users; your editor can live with that just fine, but others may feel differently. Beancount also provides a way to perform SQL-like queries on the database, which can be useful for extracting certain kinds of data.

It is worth noting that beancount is generally quick at generating reports, despite reading data from a large text file. Indeed, it is rather quicker than QuickBooks, which is faint praise but still a good thing. Still, it seems clear that the plain-text file will slow things down at some point; indeed, the beancount maintainer recently said that he's beginning to find things a bit too slow.

There is no concept of customers or vendors, so if one needs to store related information (addresses, payment terms, tax ID numbers, etc.) that information must be kept elsewhere.

One feature that isn't useful for LWN but which might be for others is the ability to track "held values" for commodities. Its primary purpose appears to be to ease the calculation of capital gains on investment transactions (investment tracking seems to be one of the main use cases for beancount's developers), but it could be put to use in any situation where one needs to track a price change between the purchase and the sale of a commodity.

Another important task is providing data to the accountant for tax filings and such. Ideally, that data would be in a form that can be read directly into their (proprietary) tax software, but that feature appears to only be available in proprietary systems. Lacking that, it would still be nice to not have to print a pile of data and hand-carry it over to get one's taxes done. Beancount has the ability to "bake" the data into a set of HTML pages that can then be placed somewhere where the accountant can see them. It is, essentially, a static site generator for accounting data.

There is, alas, no ability to generate government-mandated forms from the accounting data — a common failing in free accounting systems. Beancount also lacks the ability to print checks. Your editor is aware that you youngsters out there may never have even seen a check, but they still are necessary at times in a business setting.

Community and more

A look at the beancount Mercurial repository shows a project with a steady stream of activity. The maintainer, Martin Blais, dominates the list with far more commits than anybody else, but he is also far from the only contributor to the project. If Blais were to abruptly conclude that he'd counted enough beans for a lifetime and leave the project, there is a good chance that somebody else would step up to keep things going. That, needless to say, is a good feature for a project that a company may come to depend upon.

There is a mailing list (tragically hosted on Google Groups) as well, with a fair amount of traffic. The beancount community seems to be both engaged and helpful.

Your editor has concluded that beancount is not the solution for LWN's accounting problem. Lest the criticisms in this article seem harsh, though, it is worth pointing one thing out: this was always an attempt to use beancount for a task that is somewhat beyond what it was created for. Most of the "shortcomings" listed here are a result of that mismatch. Beancount is clearly a useful tool in many settings; for those with simpler needs it may provide all that is required, and it is easily extended for those who need to do so.

Meanwhile, the search for a QuickBooks replacement goes on, hopefully with renewed momentum. Stay tuned... sooner or later a conclusion will be reached and we'll be able to close the books on proprietary accounting systems forever.

Comments (22 posted)

Page editor: Jonathan Corbet

Inside this week's LWN.net Weekly Edition

  • Briefs: eBPF overview; Emacs 26.2; Quotes; ...
  • Announcements: Newsletters; events; security updates; kernel patches; ...
Next page: Brief items>>

Copyright © 2019, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds