This year hasn't been easy for investors, and many people are concerned that a recession could be looming. To be clear, nobody knows for certain whether a recession will happen or not. But economic downturns and market slumps often go hand in hand, and there's a chance that stock prices could have further to fall.

If that's the case, is the stock market really safe right now? Or should you hold off on investing? Here's what legendary investor Warren Buffett says about investing in times like these.

Warren Buffett looking into the camera.

Image source: The Motley Fool.

How safe is the stock market?

When the market is volatile, it can be a nerve-wracking time to buy stocks. If you invest now and stock prices fall, your portfolio could immediately lose value -- which isn't exactly encouraging.

However, the market's long-term performance is far more important than the short-term ups and downs. And historically, it has an impeccable track record of recovering from crashes and recessions.

^SPX Chart

^SPX data by YCharts.

In 2008, amid the Great Recession, Warren Buffett wrote an opinion piece for The New York Times. In it, he wrote:

[F]ears regarding the long-term prosperity of the nation's many sound companies make no sense. These businesses will indeed suffer earnings hiccups, as they always have. But most major companies will be setting new profit records 5, 10 and 20 years from now.

Keeping a long-term outlook is easier said than done when we're in the thick of a downturn, but things will get better. Regardless of what happens over the coming weeks or months, the market is almost guaranteed to see positive returns over the long run.

Should you invest right now?

"A simple rule dictates my buying," Buffett continued in the Times piece. "Be fearful when others are greedy, and be greedy when others are fearful."

Right now, as stock prices continue to fall, is the time to "be greedy." The market is essentially on sale at the moment, and some stocks are priced lower than they've been in years. If you've been waiting for a more affordable time to buy, this could be your chance.

Amazon, for example, is down more than 51% from its peak. The last time it saw this type of slump was in 2008, when it fell by roughly 60% amid recession fears. For high-priced stocks like this, right now could be a once-in-a-decade investing opportunity.

"In short, bad news is an investor's best friend," wrote Buffett. "It lets you buy a slice of America's future at a marked-down price."

Now is not only a smart time to load up on quality stocks at a discount, but it can also set you up for enormous returns when the market inevitably recovers. For example, if you had invested in Amazon in 2008, you would have earned returns of more than 600% over the following three years alone as the market recovered from the Great Recession.

AMZN Chart

AMZN data by YCharts.

Of course, there are no guarantees that you'll see this type of growth. But stocks from healthy companies are far more likely to recover from a recession, and by investing now, you'll be well-positioned to take advantage of that rebound.

It's not always easy to invest when the market is falling, and if you're feeling some anxiety right now, that's normal. But downturns can be fantastic money-making opportunities, as long as you buy quality stocks and stay invested through the market's recovery period. As Buffett wrote in the Times article:

I can't predict the short-term movements of the stock market. What is likely, however, is that the market will move higher, perhaps substantially so, well before either sentiment or the economy turns up. So if you wait for the robins, spring will be over.